Change Name of :id Param in Rails Resource Routing
You can change the name of the parameter used by rails resource routing by specifying the param
option to the resource route.
For example, if we have a show endpoint:
resources :pages, only: :show
Running rake routes
will return the pages#show
url as:
/pages/:id
We can change the id
param to slug
by doing:
resources :pages, only: :show, param: :slug
Then running rake routes
will yield our new pages#show
route as:
/pages/:slug
Tweet