Rails Dispatch

Rails news delivered fresh

Presented by Engine Yard

View Question

Vote on questions you’d like to see answered by the expert contributors

Signup to ask questions or vote for the questions you’d like to see answered.

hi,

I want to use dirty object with nested attributes here is my example.

i have form having user and addresses field when i am editing user and
after updating user inside user model i am checking for any field from
user get dirty using @self.changed? method it giving me proper output in
this i am doing @self.address.changed?( I Have polymorphic association
in user and addresses) but it is giving me nil/false if address is
changed but if i am putting @self.changed? in address model it is
giving me proper output.

Please anybody explain me how to use dirty object concept with model
association or with nested attributes?

class User < ActiveRecord::Base

has_many :addresses, :as =>:addressee, :dependent => :destroy accepts_nested_attributes_for :addresses, :allow_destroy => true after_update :send_account_updated_email def send_account_updated_email self.changed //giving correct changed field name self.addresses.changed //not working self.addresses.first.changed // not working end

end

class Address < ActiveRecord::Base

belongs_to :addressee, :polymorphic => true

end

how should i do that?

Asked October 04, 2010