Johshi Johshi - 2 years ago 109
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 Source

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"
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download