I’m using nested_attributes and trying to implement the add/remove
fields on-the-fly throu ajax following Ryan B. 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 ]} %>
<%= parts_form.hidden_field :_destroy %>
<%= link_to_remove_fields “remove”, parts_form %>
<% 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 ]} %>
4: <%= f.hidden_field :_destroy %>
5: <%= link_to_remove_fields “remove”, f %>
6:
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 ]}
%>
<%= f.hidden_field :_destroy %>
<%= link_to_remove_fields “remove”, f %>
So, any help on what I am doing wrong at this point?