【发布时间】:2018-01-31 02:58:51
【问题描述】:
我的消息模型在after_create 中调用create_notifications:
def create_notifications
if Message.where(id: 3).first.present? # This message exists!
puts "Found message" # This never fires when run :after_create
else
puts "#{Message.count}" # Returns 1 in after_create, and 125 in console (it only sees the just-created message)
end
问题:Message.where(id:3) 在回调中运行时不返回任何内容。但是,它在控制台中运行时有效。此外,当我在创建消息后手动运行.create_notifications 时,它也可以工作。
为什么Message.where、Message.count等在after_create中运行时不起作用?
【问题讨论】:
标签: ruby-on-rails activerecord callback