【发布时间】:2013-03-22 15:33:27
【问题描述】:
我有两张表:People和Car:
Person has_many cars-
Car belongs_to person。
当汽车的license_plate 发生变化时,我想向该人发送电子邮件。
我已成功创建邮件代码,但在after_save 回调中设置if 条件时遇到问题。
#Inside Person models
after_save :send_mail_notification, if: (self.cars.first.order('updated_at DESC').changed?)
def send_mail_notification(person)
...
end
我收到了这个错误
NoMethodError: undefined method `cars' for #<Class:0x4852ba8>
所以,我猜self 不能用于回调?有什么解决办法吗?
谢谢
【问题讨论】:
标签: ruby-on-rails ruby ruby-on-rails-3 conditional-statements