On Wednesday, May 25, 2011 9:06:49 AM UTC-6, Mlle wrote: > > If I wanted to write my own db trigger using a 'before_save" callback, > how would I get the before save and after save values? > > Thanks!
By "before save and after save values" do you mean the original, unchanged value(s) of the propert(y|ies) and the new, changed value(s)? If so, you might be interested in #changed_attributes. If you call this on a model instance, it returns a hash where the keys are the names of the model attributes that have changed and the associated values are original values. For example: > x = User.find(1) => #<User id: 1, name: "Bill", ...> > x.changed? => false > x.name => "Bill" > x.name = "Fred" => "Fred" > x.changed? => true > x.changed_attributes => { "name" => "Bill" } > x.save => true > x.changed? => false > x.changed_attributes => {} For more information: http://api.rubyonrails.org/classes/ActiveModel/Dirty.html -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.