确定ActiveRecord对象是否为New


Answers:



360

ActiveRecord对象生命周期:

1. 新纪录

item = Item.new
item.new_record? #=> true

2. 坚持

item.save
item.persisted? #=> true

3. 变了

item.name = "other"
item.changed? #=> true

4. 摧毁

item.destroy
item.destroyed? #=> true

28
更好的答案是,它完成了生命周期。
尼克
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.