Nate Bird
Nate Bird

Reputation: 5335

Where can I find details about the 'save' method used in rails?

I'm not sure if this is a rails method or a ruby method but I am looking for details about what happens when you call @object.save.

Upvotes: 2

Views: 6201

Answers (1)

John Topley
John Topley

Reputation: 115392

http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-save

  • save is a Rails method defined within the ActiveRecord::Persistence module. It saves the model. If the model is new, a record gets created in the database, otherwise the existing record gets updated.

  • By default, save always run validations. If any of them fail the action is cancelled and save returns false. However, if you supply :validate => false, validations are bypassed altogether.

  • There’s a series of callbacks associated with the save method. If any of the before_* callbacks return false the action is cancelled and save returns false.

  • The save! (bang) method always runs validations but raises an ActiveRecord::RecordInvalid exception upon validation failure.

Upvotes: 8

Related Questions