Question

I want to be able in browsing bar see full path to some product. The path would look like this

www.mysite.com/categories/category_name/subcategory_name/product_name

At this moment I have just www.mysite.com/categories/category_name It just provides with one level path, that I don't need.

To build these friendly links I used friendly_id. And full categorization function I created using gem called Ancestry.

How can I modify friendly_id slug so that I can show the full path? I know how the friendly_id works, but I don't know how to change the way how slug is generated.

Some guys could just give me link or tip to search for. I can work it out, I just need idea. I would be very greatfull :) :)

Was it helpful?

Solution

You can pass a method for the gem to use, as in:

extend FriendlyId
friendly_id :method_name, use: :slugged

def method_name

end

OTHER TIPS

You're probably looking for nested resouces. If both models (category, subcategory) have slugs, nesting them in your routes.rb file should do the trick:

resources :categories do
  resources :subcategories
end
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top