How to know whether a model is new or not?

Solution 1:

post.new_record?

Solution 2:

ActiveRecord's new_record? method returns true if the object hasn't been saved yet.

  • new_record? documentation