I’m writing some ActiveRecord callbacks, which need to check a few attributes for changes.
after_save :do_work
def do_work
return unless saved_change_to_name? || saved_change_to_description? || saved_change_to_favorite_superhero?
# Important code...
# ...
end
It looks pretty wordy, and feels like Rails could support saved_changes_to_any_attribute?(:name, :description, :favorite_superhero)
, and possibly saved_changes_to_attributes?(:name, ...)
to detect a change to all.
I’d be happy to make a PR for this, if it seems like a useful addition?
Thanks!