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

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

python - cx_oracle unable to find Oracle Client -