Search code examples
ruby-on-rails-4friendly-id

friendly-id custom url in rails


I have successfully integrated friendly-id and is working fine. My product can be viewed from (localhost:3000/product/test-product) url. What I want is to have a short url like (localhost:3000/test-product) for my product.

How can I achieve this in friendly-id or in rails.

Thank you in advance.


Solution

  • You need to create your custom route to achieve this :

    In routes.rb

    get ':id' => 'products#show', as: :product
    

    Call like

    product_path(product.slug)