module
v7.1.3.2 -
Show latest stable
-
0 notes
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0 (0)
- 3.0.9 (0)
- 3.1.0 (0)
- 3.2.1 (0)
- 3.2.8 (0)
- 3.2.13 (0)
- 4.0.2 (0)
- 4.1.8 (0)
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (0)
- 5.1.7 (0)
- 5.2.3 (0)
- 6.0.0 (0)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (38)
- 7.1.3.4 (0)
- What's this?
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_change # => "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").