Implementing versioning for a Rails app I'd like to have a view that displays all versions of a model with some extra functionality like reverting etc.
I use the paper_trail
gem for the versioning.
I know that I could do that by writing a controller function like versions
and a view for every model but I'd like to do it for all models at once. This should be possible because the model.versions
attribute is always structured identically.
Ideally the URL should look like /pages/testpage/versions
while testpage
is the page id.
This seems similar to the concept of nested routes in rails.
resources :pages do
resources :versions
end
The problems with nested routes however are:
- Needs extra configuration per model
- I cannot access the
testpage
object without knowing of which model it is an instance. I also wasn't able to find a way to determine the model since the only thing that is provided to my versions controller is the params hash.
I'm completely open to alternative solutions that might not follow my initial ideas.