On 16 August 2010 06:05, Sam Kong <[email protected]> wrote: > Hi, > > Here's a situation: > A product belongs to multiple categories and the categories are top > menus of a site.
That does not make sense, do you mean product has_many categories, or more likely category has_many products and product belongs_to category. > I want to highlight the category of a product when the product detail > page is loaded. > If there's some context, I can determine which category should be > highlighted. > (For example, I can track the categories that a user selected). > But sometimes there's no context (for example, the user visits the page > directly without getting through categories). If you have a product, @product say, then the the category of the product is @product.category, assuming you have setup the ActiveRecord relationships correctly. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

