Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7053703
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:32:15+00:00 2026-05-28T03:32:15+00:00

I would appreciate your help on this: I have 2 models: class Author <

  • 0

I would appreciate your help on this:

I have 2 models:

class Author < ActiveRecord::Base
    has_one :authornote, :foreign_key => "author_fk", :dependent => :destroy
    accepts_nested_attributes_for :authornote, :reject_if => lambda { |a| a[:note_value].blank? }, :allow_destroy => true
end

class Authornote < ActiveRecord::Base
    belongs_to :author, :foreign_key => :author_fk
end

In my form, i have got the following field_for:

<% remote_form_for @author, :url => { :controller => "authors", :action => "update_author_note" } do |f| %>
    <div>
      <% f.fields_for :authornote do |builder| %>
          <%= builder.text_area :note_value, :rows => 4, :cols => 50 %>
      <% end %>
    </div>
    <%= f.submit 'Update' %>
<%end%>

Controller code:

def update_author_note
  author_id = session[:author_id]
  @author = Author.find(author_id)

  if @author.update_attributes(params[:author])
    respond_to do |format|
       format.js 
    end
  else
     respond_to do |format|
       format.html { redirect_to add_author_note_path(:sub_id=> session[:sub_id]) }
     end
  end

end

Currently, if a user removes all the contents in the form field ‘note_value’ and update the form, the data row is still present in the ‘authornote’ table, with the column ‘note_value’ empty.

What i would like is that, if field ‘note_value’ is empty and user clicks on the update button, i would like the row with the empty column ‘note_value’ to be deleted in the ‘authornote’ table.

Any suggestion is most appreciated

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:32:16+00:00Added an answer on May 28, 2026 at 3:32 am

    What you’re trying to do is not supported by Rails as you’re trying to do it. In order for a record to be deleted through accepts_nested_attributes_for you have to pass _delete: true along with the ID of the record to be deleted. When you reject the nested records that don’t have a note_value there’s no way for Rails to know you’re trying to update those records—they’re just missing from the params entirely.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would really appreciate your help in this. I have been trying to get
I have the following issue and I would really appreciate your help: I have
I am a newbie in Matlab, so I would appreciate your help! I have
I'm new to linq so would appreciate your help with getting this left join
I'm new to regular expressions and would appreciate your help. I'm trying to put
I have an interesting problem and would appreciate your thoughts for the best solution.
I would appreciate some help with something I working on and have not done
I would appreciate any help on this issue. Lets say I want to load
I would appreciate your help in understanding a "Concurrency Example" from: http://forums.sun.com/thread.jspa?threadID=735386 public synchronized
I have hit a road block on this and would highly appreciate if someone

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.