I don't think it's necessary to call the klass method to get a new object in the helper. We can call #new or #build on the association directly like this:
ruby
new_object = f.object.send(association).new
One point that is probably obvious for most people, but confused me at first was why we would need to swap the object_id that's set in the helper for a time value in the javascript. I was thinking along the lines of: "the object_id is already unique, right?"
Well, yes and no. A unique object_id will be generated each time the helper is called to create an "add_fields" link. But that link may then be clicked multiple times. Each time it's clicked, it's going to generate a collection of nested fields named with the same object_id. Then of course, when the form is saved only one of those records is going to be created.
In case it might help someone, in Rails 4.0.0/Ruby 2.0, I was getting this error:
private method 'h' called for #<#Class:0x00000003dcd130:0x000000037ef538>
Instead of delegating h to the view_context, I called it directly like this:
ruby
defdata
products.map do |product|
[
link_to(product.name, product),
ERB::Util.h(product.category),
ERB::Util.h(product.released_on.strftime("%B %e, %Y")),
number_to_currency(product.price)
]
end
I don't think it's necessary to call the klass method to get a new object in the helper. We can call #new or #build on the association directly like this:
One point that is probably obvious for most people, but confused me at first was why we would need to swap the object_id that's set in the helper for a time value in the javascript. I was thinking along the lines of: "the object_id is already unique, right?"
Well, yes and no. A unique object_id will be generated each time the helper is called to create an "add_fields" link. But that link may then be clicked multiple times. Each time it's clicked, it's going to generate a collection of nested fields named with the same object_id. Then of course, when the form is saved only one of those records is going to be created.
In case it might help someone, in Rails 4.0.0/Ruby 2.0, I was getting this error:
private method 'h' called for #<#Class:0x00000003dcd130:0x000000037ef538>
Instead of delegating h to the view_context, I called it directly like this:
Changing the pasted in navigation code to this worked for me:
I'm seeing the same thing. The right navigation elements disappear when the page is narrow.