我有两个不同的 after_create 回调。我只希望在创建的记录中存在一个字段时运行一个
我知道怎么做,但我不太明白语法
#rental.rb
after_create :delete_booking , :if => ":booking_no = 'NOT NULL'"
after_create :set_requires_allocation
def delete_booking
@booking = Booking.where(:booking_no => self.booking_no).first
@booking.destroy
end
def set_requires_allocation
self.user.requires_allocation = 'false'
end
通过将用户表中的“true”更改为“false”,set_requires_allocation 是否真的会达到我认为的效果?
谢谢
最佳答案
after_create :delete_booking, :if => Proc.new { |rental| rental.booking_no.present? }
关于ruby-on-rails - 为不同的事件运行两个不同的 after_create 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13794549/