method
attribute_will_change!
v4.1.8 -
Show latest stable
- Class:
ActiveModel::Dirty
attribute_will_change!(attr)private
Handle *_will_change! for method_missing.
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