How to know whether a model is new or not?
class Post < ActiveRecord::Base
end
post = Post.new
How do I judge whether the 'post' is a new model which is not pulled from the databas开发者_StackOverflow中文版e?
post.new_record?
ActiveRecord's new_record?
method returns true
if the object hasn't been saved yet.
- new_record? documentation
you can use post.persisted? as well, if it return false means record in new
persisted?
精彩评论