RailsCasts Pro episodes are now free!
Learn more or hide this
GitHub User: ddrake
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:
new_object = f.object.send(association).new
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:
products.map do |product|
ERB::Util.h(product.released_on.strftime("%B %e, %Y")),
Changing the pasted in navigation code to this worked for me:
<h1><%= link_to "Awesome Store", products_path %></h1>
<li class="toggle-topbar menu-icon"><a href="#"><span>menu</span></a></li>
<li><%= link_to "Browse Products", products_path %></li>
<li><%= link_to "Price List" %></li>
<li><%= link_to "Contact Us" %></li>
<li><%= link_to "Cart" %></li>
I'm seeing the same thing. The right navigation elements disappear when the page is narrow.