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 database?
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 database?
ActiveRecord's new_record?
method returns true
if the object hasn't been saved yet.
you can use post.persisted? as well, if it return false means record in new