开发者

Rails is there a way to say @object.created?

开发者 https://www.devze.com 2023-03-16 04:17 出处:网络
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?

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消