module Dirty
Ruby on Rails 8.1.2
Since v3.0.20Active 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").
Includes
Extends
Methods (defined here)
- # attribute_before_last_save
- # attribute_change_to_be_saved
- # attribute_in_database
- # attributes_in_database
- # changed_attribute_names_to_save
- # changes_to_save
- # has_changes_to_save?
- # reload
- # saved_changes
- # saved_changes?
- # saved_change_to_attribute
- # saved_change_to_attribute?
- # will_save_change_to_attribute?
Private methods
(6)
Implementation detail — not part of the public API.
Used by
Included by (1)
Methods (inherited)
From ActiveModel::Dirty (22)
-
#
*_change -
#
*_changed? -
#
*_previous_change -
#
*_previously_changed? -
#
*_previously_was -
#
*_was -
#
*_will_change! - # attribute_changed?
- # attribute_previously_changed?
- # attribute_previously_was
- # attribute_was
- # changed
- # changed?
- # changed_attributes
- # changes
- # changes_applied
-
#
clear_*_change - # clear_attribute_changes
- # clear_changes_information
- # previous_changes
-
#
restore_*! - # restore_attributes
From ActiveSupport::Concern (3)
- # class_methods
- # included
- # prepended