Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 5db2f199aba9aa8d00adefa8237922ad684aca03 1 parent eaa9c06
Xavier Noria fxn authored

Showing 1 changed file with 30 additions and 12 deletions. Show diff stats Hide diff stats

  1. +30 12 activerecord/lib/active_record/base.rb
42 activerecord/lib/active_record/base.rb
@@ -2237,22 +2237,40 @@ def new_record?
2237 2237 defined?(@new_record) && @new_record
2238 2238 end
2239 2239
2240   - # * No record exists: Creates a new record with values matching those of the object attributes.
2241   - # * A record does exist: Updates the record with values matching those of the object attributes.
2242   - #
2243   - # Note: If your model specifies any validations then the method declaration dynamically
2244   - # changes to:
2245   - # save(perform_validation=true)
2246   - # Calling save(false) saves the model without running validations.
2247   - # See ActiveRecord::Validations for more information.
  2240 + # :call-seq:
  2241 + # save(perform_validation = true)
  2242 + #
  2243 + # Saves the model.
  2244 + #
  2245 + # If the model is new a record gets created in the database, otherwise
  2246 + # the existing record gets updated.
  2247 + #
  2248 + # If +perform_validation+ is true validations run. If any of them fail
  2249 + # the action is cancelled and +save+ returns +false+. If the flag is
  2250 + # false validations are bypassed altogether. See
  2251 + # ActiveRecord::Validations for more information.
  2252 + #
  2253 + # There's a series of callbacks associated with +save+. If any of the
  2254 + # <tt>before_*</tt> callbacks return +false+ the action is cancelled and
  2255 + # +save+ returns +false+. See ActiveRecord::Callbacks for further
  2256 + # details.
2248 2257 def save
2249 2258 create_or_update
2250 2259 end
2251 2260
2252   - # Attempts to save the record, but instead of just returning false if it couldn't happen, it raises an
2253   - # ActiveRecord::RecordNotSaved exception. However, if the callback chain raises ActiveRecord::Rollback
2254   - # to rollback the transaction that wraps <tt>save!</tt> no exception is raised, <tt>save!</tt> just
2255   - # returns +nil+. See ActiveRecord::Callbacks for further details.
  2261 + # Saves the model.
  2262 + #
  2263 + # If the model is new a record gets created in the database, otherwise
  2264 + # the existing record gets updated.
  2265 + #
  2266 + # With <tt>save!</tt> validations always run. If any of them fail
  2267 + # ActiveRecord::RecordInvalid gets raised. See ActiveRecord::Validations
  2268 + # for more information.
  2269 + #
  2270 + # There's a series of callbacks associated with <tt>save!</tt>. If any of
  2271 + # the <tt>before_*</tt> callbacks return +false+ the action is cancelled
  2272 + # and <tt>save!</tt> raises ActiveRecord::RecordNotSaved. See
  2273 + # ActiveRecord::Callbacks for further details.
2256 2274 def save!
2257 2275 create_or_update || raise(RecordNotSaved)
2258 2276 end

0 comments on commit 5db2f19

Please sign in to comment.
Something went wrong with that request. Please try again.