0

I have the following code in my layout file:

<% @families = ProductFamily.find(:all, :include => :products) %>
<% @families.each do |f| %>

    <h2><%=h f.name %></h2>
    <ul>
    <% f.products.each do |product| %>
        <li><%=h product.name %></li>
    <% end %>
    </ul>
<% end %>

Two things: I doubt this follows standard MVC procedures, so any help on making it so would be a huge plus. But most importantly, the product name is not being displayed. Instead, the model name (or so I assume) is being shown in its place (i.e. "Product"). I know it is looping through all of the products, because the right number of lines is being shown--just not the actual product name.

Any suggestions? Thanks in advance.

2 Answers 2

1

If you need @families application wide. You should define a before_filter in the application_controller

class ApplicationController < ActionController::Base

  before_filter :get_product_families        

  private 
  def get_product_families
    @families = ProductFamily.find(:all, :include => :products)    
  end

end

And for your other problem, we need some more info. Put a inspect on the product, your current view code should work.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, the before_filter was something I desperately needed.
1

put

@families = ProductFamily.find(:all, :include => :products)

in your controller.

try

<%= h product.inspect %>

and ensure that name is what you are expecting.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.