I'm using nested_attributes and trying to implement the add/remove fields on-the-fly throu ajax following Ryan Bates screencast about Nested Model (#196)
Doing this, it works fine:
<%= f.fields_for :item_parts do |parts_form| %> <p class="fields"> <%= parts_form.label :part_id %> <%= parts_form.select :part_id, Part.all.collect { |x| [ x.title, x.id ]} %><br /> <%= parts_form.hidden_field :_destroy %> <%= link_to_remove_fields "remove", parts_form %> </p> <% end %>
But when trying to pass the form fields to a partial like this, it returns the following error:
undefined method `part_id' for #<Part:0x00000103c4fed8>
Extracted source (around line #3):
1: <p class="fields"> 2: <%= f.label :part_id %> 3: <%= f.select :part_id, Part.all.collect { |x| [ x.title, x.id ]} %><br /> 4: <%= f.hidden_field :_destroy %> 5: <%= link_to_remove_fields "remove", f %> 6: </p>
The relevant code for the form calls the partial:
<%= f.fields_for :item_parts do |parts_form| %> <%= render 'part_fields', :f => parts_form %> <% end %>
partial: /part_fields.html.erb
<p class="fields"> <%= f.label :part_id %> <%= f.select :part_id, Part.all.collect { |x| [ x.title, x.id ]} %><br /> <%= f.hidden_field :_destroy %> <%= link_to_remove_fields "remove", f %> </p>
So, any help on what I am doing wrong at this point?