simple form - Ruby on Rails, undefined method `name' for nil:NilClass when deleting association -


i using rails 3.2.13 have 3 entities

mother

class mother < activerecord::base     attr_accessible :previous_births_attributes     belongs_to :participant     has_many :previous_births     accepts_nested_attributes_for :previous_births, :reject_if => :all_blank, allow_destroy: true end 

previousbirth

class previousbirth < activerecord::base   attr_accessible :gender   belongs_to :mother end     

i displayed view using cocoon

_form.html.erb

<div id='previous-births'>   <%= f.simple_fields_for :previous_births |task| %>       <%= render 'previous_birth_fields', :f => task %>   <% end %>   <%= link_to_add_association 'add previous birth', f, :previous_births, class: 'btn btn-success btn-mini ' %>       </div> 

_previous_birth_fields.html.erb

<div class="nested-fields row">   <table class="table table-compact span12">     <thead>      <tr>        <th class="span1">gender</th>        <th class="span1">&nbsp;</th>      </tr>   </thead>   <tbody>     <tr>       <td><%= f.input_field :gender, collection: ["female", "male"], :class => "span1" %></td>       <td><%= link_to_remove_association "remove", f, class: 'btn btn-danger btn-small span1' %></td>     </tr>   </tbody> 

adding previous_birth works charm. when remove association during update,

nomethoderror (undefined method name' nil:nilclass): app/controllers/mothers_controller.rb:71:inblock in update' app/controllers/mothers_controller.rb:70:in `update'

mothers_controllers.rb

def update   @mother = mother.find(params[:id])   participant = @mother.participant   authorize participant   respond_to |format|   if @mother.update_attributes(params[:mother]) #line 71     format.html { redirect_to @mother.participant, notice: 'mother updated.' }     format.json { head :no_content }   else     format.html { render action: "edit" }     format.json { render json: @mother.errors, status: :unprocessable_entity }   end end 

i not have attribute called name in either mother or previous birth entities. tried google it, found nothing. have idea?

thank you


Comments