Episodes
Johan André PRO said over 2 years ago on Tracking Changes on Action Text :
Nice!
One thing though - you could probably use the Current

class of ActiveSupport to track the current user.
https://fullstackheroes.com/rails/current-attributes/

David Kimura PRO said over 2 years ago on Tracking Changes on Action Text :
Cool   ! Rails provides so much. I could spend days just reading the docs and learn so much.

jablko said over 2 years ago on Tracking Changes on Action Text :
Hi Dave,

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:

irb(main):001:0> a = 'b'
=> "b"
irb(main):002:0> a = nil if false
=> nil
irb(main):003:0> a
=> "b"

Adding brackets would do the trick: CurrentScope.user = (current_user if user_signed_in?) or:

  def user_for_version
    CurrentScope.user = current_user if user_signed_in?
    yield
    CurrentScope.user = nil
  end

tbcooney PRO said over 2 years ago on Tracking Changes on Action Text :
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."

tbcooney PRO said over 2 years ago on Tracking Changes on Action Text :
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


David Kimura PRO said over 2 years ago on Tracking Changes on Action Text :
  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.

tbcooney PRO said over 2 years ago on Tracking Changes on Action Text :
  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."?

David Kimura PRO said over 2 years ago on Tracking Changes on Action Text :
  You should be able to have a controller action with the content

version = Version.includes(:item).find(params[:id])
itemable = version.item
itemable.content = version.content
itemable.save

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.

Rocela Durazo said over 2 years ago on Tracking Changes on Action Text :
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 ? 

David Kimura PRO said over 2 years ago on Tracking Changes on Action Text :
  You can do that with something existing like paper_trail. Or for other attributes, you could role your own solution as a concern; similar to what we did in this episode. https://www.driftingruby.com/episodes/auditing-with-paper-trail


Login to Comment