Johshi Johshi - 3 months ago 7
Ruby Question

Changing "show" and "edit" for resources

I have this in routes:

resources :resource1


I want to add a parameter to "edit" and "show" in the url and only to "edit" and "show". Say, I want to add a date to the url so it'll look like "resource1/2016-05-12/123" for "show". How can I do that?

Answer

You can exclude routes from the resources definition:

resources :resource1, except: [:edit, :show]

Then write custom definitions for those routes:

get "/resource/:date/:id", to: "resource1#edit"
put "/resource/:date/:id", to: "resource1#edit"