views:

116

answers:

2

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 advanced.

+1  A: 

put

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

in your controller.

try

<%= h product.inspect %>

and ensure that name is what you are expecting.

Ben Hughes
+1  A: 

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.

Michel de Graaf
Thanks, the before_filter was something I desperately needed.
Joshua Cohen