Rails: how to check if find_or_initialize is updating/creating/skipping?
ruby-on-rails
Solution
To check if `book` was changed there's `changed?`:
book.changed?
To check if `book` is a new record there's `new_record?`:
book.new_record?
Problem
I have method which updating data in database from CSV. ``` csv_text = File.read("#{Rails.root}/db/seed/books.csv") csv = CSV.parse(csv_text, :headers => :first_row) csv.each { |row| row = row.to_hash.with_indifferent_access.to_hash.symbolize_keys row.delete_if { |key, value| value.nil? } book = Book.find_or_initialize_by_name(row[:name]) book.update_attributes!(row) ``` How can i check if record will be created or updated or nothing happens?