Flowdock
method

attribute_will_change!

Importance_1
v3.1.0 - Show latest stable - 1 note - Class: ActiveModel::Dirty
attribute_will_change!(attr) private

Handle *_will_change! for method_missing.

Show source
Register or log in to add new notes.
January 26, 2011 - (>= v3.0.0)
2 thanks

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