module
ActiveRecord::AttributeMethods::Dirty
v8.1.1 -
Show latest stable
Active Record Attribute Methods Dirty
Provides a way to track changes in your Active Record models. It adds all methods from ActiveModel::Dirty and adds database-specific methods.
A newly created Person object is unchanged:
class Person < ActiveRecord::Base end person = Person.create(name: "Allison") person.changed? # => false
Change the name:
person.name = 'Alice' person.name_in_database # => "Allison" person.will_save_change_to_name? # => true person.name_change_to_be_saved # => ["Allison", "Alice"] person.changes_to_save # => {"name"=>["Allison", "Alice"]}
Save the changes:
person.save person.name_in_database # => "Alice" person.saved_change_to_name? # => true person.saved_change_to_name # => ["Allison", "Alice"] person.name_before_last_save # => "Allison"
Similar to ActiveModel::Dirty, methods can be invoked as saved_change_to_name? or by passing an argument to the generic method saved_change_to_attribute?("name").
Included modules
- ActiveModel::Dirty
Files
- activerecord/lib/active_record/attribute_methods/dirty.rb