Getting the id of the object when inside form_for or fields_for
ruby-on-rails
Solution
I found the answer:
f.object.id
Problem
I have the following code that is generating fields for an invoice THis is in the edit.html.erb for the invoice class ``` <% f.fields_for(:invoice_items) do |f| %> <%= render :partial => 'invoice_items/fields', :locals => {:f => f} %> <% end %> ``` and I generate the invoice_items as part of the invoice object ``` @invoice = Invoice.find(params[:id], :include => :invoice_items, :order =>"invoice_items.display_order") ``` It works just fine, but I need to wrap each one in a div, and assign that object's id to the div. (div id=i_2345 - that kind of thing) so I can use jQuery wizardry. Where I am stumbling like a new-born foal is how do I access the the id of the invoice_item that is being called? I can do a f.text_field :id and it gives me the correct id - so it knows it. But I am hoping there is some rails magic pixie dust I can sprinkle that will give it to me without having to rip that apart.