我無法弄清楚如何檢查記錄是否新保存。現在我使用檢查是否新創建記錄
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