我无法弄清楚如何检查记录是否新保存。现在我使用检查是否新创建记录
If @item.save
@a = Item.where(“restaurant_id = ?”, params[:item][:user_id]).where(“created_at < ?”, 2.minutes.ago)
查询工作正常,但我不知道是否有更好的方法来检查,看看是否记录刚刚创建。我正在查看ActiveModel :: Dirty,但一旦记录被保存,:created_at_changed?将返回false。
退房这个问题的答案+:http://stackoverflow.com/questions/7842920/determine-if-activerecord-object-is-新或创建 – Mattherick
甚至http://stackoverflow.com/questions/7842920/determine-if-activerecord-object-is-new-or-created – msbarnard