Question

I am using a great gem called paper_trail. I have created a page called 'history' that will list the versions for any resource. My routes file has a nested resource for EVERY route...which is not DRY at all.

resources :users do 
  get "/history" => "pages#history", as: "history"
end

this route gives me users/1/history

resources :companies do 
  get "/history" => "pages#history", as: "history"
end

now I have companies/1/history

How can I make the /history work as a nested route for ALL routes without filling my routes file with a nested history path for every resource?

Was it helpful?

Solution

You can do these types of actions in a block to avoid repeating yourself over and over.

resources :users, :companies do 
  get "history" => "pages#history", :on => :member
end

Some additional helpful information is available on this SO question.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top