views:

25

answers:

1

I have three models. User, Product, and Season.

I used a standard "has many through" approach:

user has_many :seasons
user has_many :products, :through => :seasons

product has_many :seasons
product has_many :users, :through => :seasons

seasons belong_to :product
seasons belong_to :user

On my "show" view for my users, I display the user's products. I do this as follows:

    <% @user.seasons.each do |c| %>
      <%=h c.product.name %>
    <% end %>

This all works great.

Here's my question. How do I create a hyperlink to the show view of whatever product is generated by this code <%=h c.product.name %>? I followed the API and tried using a block, but none of my attempts worked properly.

+1  A: 
  <% @user.seasons.each do |c| %>
    <%= link_to c.product.name, c.product %>
  <% end %>
Lichtamberg
Great. That worked. Thanks.
MikeH