开发者

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

开发者 https://www.devze.com 2023-01-23 06:38 出处:网络
I\'m not sure if this is a rails method or a ruby method but I am looking f开发者_Python百科or details about what happens when you call @object.save.http://api.rubyonrails.org/classes/ActiveRecord/Per

I'm not sure if this is a rails method or a ruby method but I am looking f开发者_Python百科or details about what happens when you call @object.save.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消