This is a great episode! The Lockbox gem recently added support for Action Text Rich Text snippets to encrypt them. ☒ would it be possible to restore a version of an article record? Basecamp does something similar to this episode, where a Document has many Document::Version and the user can see an updated view of all the changes that have happened to the document. For restoring a version, you can open up a Document::Version and click a button to "Make this the current version."
I think it wouldn't justify it's own controller, and `restore` could be an action on the `Document::VersionsController`. The route might look like this, but I'm not sure what the logic in that method would look like.
# config/routes.rb
resources :articles do
scope module: 'articles' do
resources :versions do
post :restore, on: :member
end
end
☒ I would actually prefer a separate controller. When I first started out development, I would have several compromises with my controllers. First they were fat controllers, then they had various actions outside of the standards and so on. These all seemed fine until I had to go back and work on these older applications and these kinds of patterns were a pain to go back and work in. So, I would actually have a different controller and in this particular case, I would not have it dependent on articles. I would have probably do something like
resources :versions, only: [] do
resource :restore
end
The reason why I would prefer leaving the article out of it is that the polymorphic association in the Version table already knows who the item belongs to. So, we can look up that item and do the necessary checks. I also like this way because then we can write it one time, and not have to worry about all of the different Action Text attributes used by other models; this solution would work for all of them.
☒ well said, and I agree with those points. Have you an idea what the logic in the RestoreController might look like to allow a user to "restore" a prior version to "Make this the current version."?
Hi Dave, wondering if we want to track a version of an article when the title change, is it posible to found if the record.title change in the initializer or how can we achieve this ?
One thing though - you could probably use the Current
https://fullstackheroes.com/rails/current-attributes/
great episode :)
In application_controller when you assign current user you don't clear the user variable, so it keeps the last logged user. Take a look:
Adding brackets would do the trick: CurrentScope.user = (current_user if user_signed_in?) or:
The reason why I would prefer leaving the article out of it is that the polymorphic association in the Version table already knows who the item belongs to. So, we can look up that item and do the necessary checks. I also like this way because then we can write it one time, and not have to worry about all of the different Action Text attributes used by other models; this solution would work for all of them.
It should take the content of the version and set it to the related content. This of course would then create a new version based on this version.