Can Rails ActiveRecord #save method be used to update an existing record?

This question already has an answer here:

  • how does activerecord know to perform an insert or update?

    3 answers

  • How do I sort on an association of a specific user?
  • Rails rake db:migrate has no effect
  • Rails: Combining two different ActiveRecord collections into one
  • How do I replace accented Latin characters in Ruby?
  • Rails destroy all but newest n records
  • has_many :through : How do you access join table attributes?
  • rails form_for never invokes the create controller action to use redirect_to
  • Activerecord: find record by grandparent value
  • OpenSSL::SSL::SSLError: SSL_connect SYSCALL returned=5 errno=0 state=SSLv3 read server hello A
  • The 'tap' method on String object doesn't return expected result
  • gem included in gemfile still requires “include” in class file?
  • ActiveModel::MassAssignmentSecurity::Error with nested attributes
  • 2 Solutions collect form web for “Can Rails ActiveRecord #save method be used to update an existing record?”

    Yes. An ActiveRecord object in Rails retains its identity in the ID parameter. If the ID is set, Rails will know to update the record in the database with that ID.

    save is, in fact, the primary way to create, update, or in any way save an object to the database. Other methods like update_attributes are just sugar that use save at their core.

    this is an update.

    save(perform_validation = true)

      # File vendor/rails/activerecord/lib/active_record/base.rb, line 2533
    2533:       def save
    2534:         create_or_update
    2535:       end
    Ruby is the best programming language in the world - Ruby on Rails.