Here’s a situation:
A product belongs to multiple categories and the categories are top
menus of a site.
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).
How can you solve this problem?
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.
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.
Sorry.
I was not clear about this.
Product and Category are m:n relationship.
Actually there’s a Categoryship model.
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.
Sorry.
I was not clear about this.
Product and Category are m:n relationship.
Actually there’s a Categoryship model.
It would be easier if you could just supply the relationships. I
think you are saying category has_many products through categoryship
and product has_many categories through categoryship also. In that
case if you have a product then the categories are available as @product.categories. I am not sure what your question is.
The problem is that @product.categories is multiple.
I need to highlight only 1 category for the product and show only 1
breadcrumb.
If there’s some path that the user took, I can select the category but
if there’s no such context, I don’t know what to do.
I can make my own policy but I want to know how other developers are
doing.
So instead of products > category > product
you could do products > { multiple categories } > product
where the { multiple categories } is a mouseover dropdown to show
the list of relevant category links.
Yes, that will do.
Our top menus are categories.
I need to highlight the category.
Do you have any good idea for that?
The problem is that @product.categories is multiple.
I need to highlight only 1 category for the product and show only 1
breadcrumb.
If there’s some path that the user took, I can select the category but
if there’s no such context, I don’t know what to do.
I can make my own policy but I want to know how other developers are
doing.
So instead of products > category > product
you could do products > { multiple categories } > product
where the { multiple categories } is a mouseover dropdown to show
the list of relevant category links.
FWIW,
Hassan S. ------------------------ [email protected]
twitter: @hassan
Sorry.
I was not clear about this.
Product and Category are m:n relationship.
Actually there’s a Categoryship model.
It would be easier if you could just supply the relationships. I
think you are saying category has_many products through categoryship
and product has_many categories through categoryship also. In that
case if you have a product then the categories are available as @product.categories. I am not sure what your question is.
You are understanding the relationships correctly.
The problem is that @product.categories is multiple.
I need to highlight only 1 category for the product and show only 1
breadcrumb.
If there’s some path that the user took, I can select the category but
if there’s no such context, I don’t know what to do.
I can make my own policy but I want to know how other developers are
doing.