如何检查一个ActiveRecord对象是新的还是已经持久化的?
ActiveRecord
ActiveRecord 对象生命周期:
1.new record
item = Item.new item.new_record? #=> true
2.persisted
item.save item.persisted? #=> true
3.changed
item.name = "other" item.changed? #=> true
4.destroyed
item.destroy item.destroyed? #=> true