Search code examples
ruby-on-railsfriendly-idancestry

modify friendly_id gem


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 :) :)


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