Skip to content

Commit

Permalink
Merge pull request rails#52044 from p8/activerecord/tiny-description-fix
Browse files Browse the repository at this point in the history
Improve documentation of RecordNotSaved and RecordNotDestroyed [ci-skip]
  • Loading branch information
p8 authored Jun 8, 2024
2 parents 03187f6 + 18dddca commit 8d416d0
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions activerecord/lib/active_record/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,17 @@ def initialize(message = nil, model = nil, primary_key = nil, id = nil)

# Raised by {ActiveRecord::Base#save!}[rdoc-ref:Persistence#save!] and
# {ActiveRecord::Base.update_attribute!}[rdoc-ref:Persistence#update_attribute!]
# methods when a record is failed to validate or cannot be saved due to any of the
# methods when a record failed to validate or cannot be saved due to any of the
# <tt>before_*</tt> callbacks throwing +:abort+. See
# ActiveRecord::Callbacks for further details
# ActiveRecord::Callbacks for further details.
#
# class Product < ActiveRecord::Base
# before_save do
# throw :abort if price < 0
# end
# end
#
# Product.create! # => raises an ActiveRecord::RecordNotSaved
class RecordNotSaved < ActiveRecordError
attr_reader :record

Expand All @@ -143,15 +151,17 @@ def initialize(message = nil, record = nil)
end

# Raised by {ActiveRecord::Base#destroy!}[rdoc-ref:Persistence#destroy!]
# when a call to {#destroy}[rdoc-ref:Persistence#destroy]
# would return false.
# when a record cannot be destroyed due to any of the
# <tt>before_destroy</tt> callbacks throwing +:abort+. See
# ActiveRecord::Callbacks for further details.
#
# begin
# complex_operation_that_internally_calls_destroy!
# rescue ActiveRecord::RecordNotDestroyed => invalid
# puts invalid.record.errors
# class User < ActiveRecord::Base
# before_destroy do
# throw :abort if still_active?
# end
# end
#
# User.first.destroy! # => raises an ActiveRecord::RecordNotDestroyed
class RecordNotDestroyed < ActiveRecordError
attr_reader :record

Expand Down

0 comments on commit 8d416d0

Please sign in to comment.