Permalink
Browse files

Reworded and corrected docs of AR#save and AR#save!

  • Loading branch information...
1 parent eaa9c06 commit 5db2f199aba9aa8d00adefa8237922ad684aca03 @fxn fxn committed Aug 26, 2008
Showing with 30 additions and 12 deletions.
  1. +30 −12 activerecord/lib/active_record/base.rb
@@ -2237,22 +2237,40 @@ def new_record?
defined?(@new_record) && @new_record
end
- # * No record exists: Creates a new record with values matching those of the object attributes.
- # * A record does exist: Updates the record with values matching those of the object attributes.
- #
- # Note: If your model specifies any validations then the method declaration dynamically
- # changes to:
- # save(perform_validation=true)
- # Calling save(false) saves the model without running validations.
- # See ActiveRecord::Validations for more information.
+ # :call-seq:
+ # save(perform_validation = true)
+ #
+ # Saves the model.
+ #
+ # If the model is new a record gets created in the database, otherwise
+ # the existing record gets updated.
+ #
+ # If +perform_validation+ is true validations run. If any of them fail
+ # the action is cancelled and +save+ returns +false+. If the flag is
+ # false validations are bypassed altogether. See
+ # ActiveRecord::Validations for more information.
+ #
+ # There's a series of callbacks associated with +save+. If any of the
+ # <tt>before_*</tt> callbacks return +false+ the action is cancelled and
+ # +save+ returns +false+. See ActiveRecord::Callbacks for further
+ # details.
def save
create_or_update
end
- # Attempts to save the record, but instead of just returning false if it couldn't happen, it raises an
- # ActiveRecord::RecordNotSaved exception. However, if the callback chain raises ActiveRecord::Rollback
- # to rollback the transaction that wraps <tt>save!</tt> no exception is raised, <tt>save!</tt> just
- # returns +nil+. See ActiveRecord::Callbacks for further details.
+ # Saves the model.
+ #
+ # If the model is new a record gets created in the database, otherwise
+ # the existing record gets updated.
+ #
+ # With <tt>save!</tt> validations always run. If any of them fail
+ # ActiveRecord::RecordInvalid gets raised. See ActiveRecord::Validations
+ # for more information.
+ #
+ # There's a series of callbacks associated with <tt>save!</tt>. If any of
+ # the <tt>before_*</tt> callbacks return +false+ the action is cancelled
+ # and <tt>save!</tt> raises ActiveRecord::RecordNotSaved. See
+ # ActiveRecord::Callbacks for further details.
def save!
create_or_update || raise(RecordNotSaved)
end

0 comments on commit 5db2f19

Please sign in to comment.