module Dirty

Ruby on Rails 7.1.6

Since v3.0.20

Available in: v3.0.20 v3.1.12 v3.2.22.5 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

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").

Includes

Extends

Methods (defined here)

Private methods

(6) Implementation detail — not part of the public API.

Used by

Included by (1)

Methods (inherited)

From ActiveModel::Dirty (22)
From ActiveSupport::Concern (3)
From ActiveModel::AttributeMethods (4)

Type at least 2 characters to search.

↑↓ navigate · open · esc close