method
attribute_will_change!
v7.1.3.4 -
Show latest stable
- Class:
ActiveModel::Dirty
attribute_will_change!(attr_name)private
Dispatch target for *_will_change! attribute methods.
1Note
Use this for validatating nested forms
When you create a nested form, and want the main object to validate all nested models, you should make all the nested models dirty or validations will not run upon them.
class Order < ActiveRecord::Base
has_many :order_lines
accepts_nested_attributes_for :order_lines
before_validation :mark_order_lines_as_changed
private
def mark_order_lines_as_changed
order_lines.each(&:updated_at_will_change!)
end
end