Rails, in the model is there a way to provide a dif since the last update? -


given model like:

class sentenceitem < activerecord::base    after_update :send_changes    def send_changes      #### possible diff here dirty/changed? showing what's changed since last save?   end  end 

and sentence modle has text field.

is possible diff here dirty/changed? showing what's changed since last save?

thanks

yes, there way. activemodel::dirty documentation:

a newly instantiated object unchanged:

person = person.find_by_name('uncle bob') person.changed?       # => false 

change name:

person.name = 'bob' person.changed?       # => true person.name_changed?  # => true person.name_was       # => 'uncle bob' person.name_change    # => ['uncle bob', 'bob'] person.name = 'bill' person.name_change    # => ['uncle bob', 'bill'] 

which attributes have changed?

person.name = 'bob' person.changed        # => ['name'] person.changes        # => { 'name' => ['bill', 'bob'] } 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -