On Aug 4, 2011, at 4:24 PM, Kleber Shimabuku wrote:

A friend of mine just realize that the problem is related to the
javascript add function.

And now I'm trying to fix it.

 <div><%= add_child_link "Add Part", f, :item %></div>

Look outside of this line. Are you sure you are inside of the `form_for @your_model do |f|` loop at the moment you see this line? The error sounds like you're outside of it, and thus builder.object (inside the helper) doesn't resolve to @ your_model.

Walter


on my Item model I hold the accepts_nested_attributes_for :item_parts

but I still getting a error

undefined method `klass' for nil:NilClass

this error refers to the object variable on this:

 def add_child_link(name, form_builder, association)
   object =
form_builder .object.class.reflect_on_association(association).klass.new
...
end


any help?





On Aug 4, 8:13 pm, Kleber Shimabuku <[email protected]> wrote:
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?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails- [email protected]. To unsubscribe from this group, send email to [email protected] . For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en .


--
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to