instance method will_save_change_to_attribute?

Ruby on Rails 7.0.10

Since v5.2.8.1

Available in: v5.2.8.1 v6.0.6 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3 v8.0.4 v8.1.2

Signature

will_save_change_to_attribute?(attr_name, **options)

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.

Parameters

attr_name req
options keyrest
Source
# File activerecord/lib/active_record/attribute_methods/dirty.rb, line 132
      def will_save_change_to_attribute?(attr_name, **options)
        mutations_from_database.changed?(attr_name.to_s, **options)
      end

Defined in activerecord/lib/active_record/attribute_methods/dirty.rb line 132 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::AttributeMethods::Dirty

Type at least 2 characters to search.

↑↓ navigate · open · esc close