Method: ActiveRecord::AttributeMethods::Dirty#will_save_change_to_attribute?
- Defined in:
- lib/active_record/attribute_methods/dirty.rb
#will_save_change_to_attribute?(attr_name, **options) ⇒ Boolean
Will this attribute change the next time we save?
This method is useful in validations and before callbacks to determine if the next call to save
will change a particular attribute. It can be invoked as will_save_change_to_name?
instead of will_save_change_to_attribute?("name")
.
Options
from
-
When specified, this method will return false unless the original value is equal to the given value.
to
-
When specified, this method will return false unless the value will be changed to the given value.
138 139 140 |
# File 'lib/active_record/attribute_methods/dirty.rb', line 138 def will_save_change_to_attribute?(attr_name, **) mutations_from_database.changed?(attr_name.to_s, **) end |