Search code examples
ruby-on-rails-4custom-routes

resource routes to be mapped to a custom path in rails 4


I have a route like:

resources :products

Now I have all my code is in place but just need to change the paths from /products/:action to /items/:action

I have already skimmed through the rails docs but could not figure this out. It looks very basic and should be easy, but I just cant put my finger on it.

The url I used was: http://guides.rubyonrails.org/routing.html#path-and-url-helpers


Solution

  • You can write your route like this:

    resources :products, path: 'items'
    

    This will generate /items routes with product_* named helpers, using ProductsController. Have a look at this part of the Routing Guides.