Sometimes we need to determine whether an ActiveRecord object is new or not. An example would be if we use first_or_initialize. In order to do this, all you need to do is use the new_record? method. For example:

book = Books.where(isbn: "0374180660").first_or_initialize
if book.new_record? # => true if book is new, false if it wasn't.
  # Perform misc stuff here.
end