Sign in through GitHub

Please read for an updated status on RailsCasts:

Learn more or hide this

Dow Drake's Profile

GitHub User: ddrake

Site: http://dowdrake.com

Comments by Dow Drake

Avatar

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.

Avatar

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
def data
  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
Avatar

Changing the pasted in navigation code to this worked for me:

html
<nav class="top-bar">
  <ul class="title-area">
    <li class="name">
      <h1><%= link_to "Awesome Store", products_path %></h1>
    </li>
    <li class="toggle-topbar menu-icon"><a href="#"><span>menu</span></a></li>
  </ul>
  <section class="top-bar-section">
    <ul class="right">
      <li class="divider"></li>
      <li><%= link_to "Browse Products", products_path %></li>
      <li class="divider"></li>
      <li><%= link_to "Price List" %></li>
      <li class="divider"></li>
      <li><%= link_to "Contact Us" %></li>
      <li class="divider"></li>
      <li><%= link_to "Cart" %></li>
    </ul>
  </section>
</nav>
Avatar

I'm seeing the same thing. The right navigation elements disappear when the page is narrow.