activemodel-attribute_changed_specification
Expand _changed? method defined in ActiveModel::Dirty. You can specify changed attribute value.
Installation
Add this gem to your Gemfile
gem 'activemodel-attribute_changed_specification'
Install via bundle
$ bundle
Usage
Specify value changes.
user = User.new
user.name = 'Bob'
user.name_changed?(from: nil, to: 'Bob') # => true
user.name_changed?(from: 'Paul', to: 'Bob') # => falseusing only from or to
user = User.new
user.name = 'Bob'
user.name_changed?(to: 'Bob') # => true
user.name_changed?(from: 'Paul') # => falseYou can still use original _changed? method.
user = User.new
user.name = 'Bob'
user.name_changed? # => trueSupports
- 3.2 <= rails < 4.1 (Rails >= supports this format by itself)