Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect if a paperclip attachment was changed in after_save callback?

It looks like Paperclip doesn't honor the ActiveRecord dirty model. How do I detect the change in after_save callback.

class User

  has_attachment :avatar    
  after_save :do_something

  def do_something
    if name_changed?
      #
    end

    # How to determine avatar was changed?
    #if avatar_changed?
    #  #
    #end

  end
end

Note

I know I can detect the change in before_save callback using avatar.dirty? call, but the dirty flag is set to false after save.

I can add a processor, but I need to perform my actions after the model data is saved.

like image 304
Harish Shetty Avatar asked Jan 27 '12 04:01

Harish Shetty


1 Answers

You could try accessing the _changed? method for one of the attributes:

if avatar_updated_at_changed?
  # do something
end
like image 169
Dylan Markow Avatar answered Oct 21 '22 18:10

Dylan Markow