I want to check before saving event so I can throw an alert everytime a specific field gets updated.
I tried to use “changed” to detect it but update_attributes shortcut the db validation so there is no way for me to use changed?
For example this notices the change:
m = Player.new
m.name = "Tom"
m.changed?
=> true
But this does not:
m = Player.new
m.update_attributes!(name: "John")
m.changed?
=> false
Any ideas how I can do this differently?
changed?returnstrueif there is non-persisted changes on your object. After your call, the object is up to date — hence thefalsereturn. Check theActiveModel::Dirtymodule, there is several utilities in it to deal with changes on object.previous_changescould do the trick, and maybe there is a more suited method to your use case.