I want to know if rails has a method that allows me to determine if the objec开发者_开发问答t is built but not created in the db or has been created?
Thanks
You want the new_record?
method:
Use it like:
object.new_record?
This will tell you that the object has been created, but not saved to the database yet.
In addition to @RyanWilcox, you can also use persisted?.
From the documentation:
Returns if the record is persisted, i.e. it’s not a new record and it was not destroyed.
精彩评论