ruby on rails - Error using `self` object in after_save callback -
i have 2 tables: people , car:
person has_many cars
car belongs_to person
.
i want send email person when license_plate
of car changed.
i have made mail code have problem in setting if
condition inside after_save
callback.
#inside person models after_save :send_mail_notification, if: (self.cars.first.order('updated_at desc').changed?) def send_mail_notification(person) ... end
i got error
nomethoderror: undefined method `cars' #<class:0x4852ba8>
so, guess self
isn't usable in callback? solution?
thanks
after_save :send_mail_notification, if: proc.new { |model| model.cars.order('updated_at desc').first.changed? }
Comments
Post a Comment