@@ -130,9 +130,17 @@ def initialize(message = nil, model = nil, primary_key = nil, id = nil)
130
130
131
131
# Raised by {ActiveRecord::Base#save!}[rdoc-ref:Persistence#save!] and
132
132
# {ActiveRecord::Base.update_attribute!}[rdoc-ref:Persistence#update_attribute!]
133
- # methods when a record is failed to validate or cannot be saved due to any of the
133
+ # methods when a record failed to validate or cannot be saved due to any of the
134
134
# <tt>before_*</tt> callbacks throwing +:abort+. See
135
- # ActiveRecord::Callbacks for further details
135
+ # ActiveRecord::Callbacks for further details.
136
+ #
137
+ # class Product < ActiveRecord::Base
138
+ # before_save do
139
+ # throw :abort if price < 0
140
+ # end
141
+ # end
142
+ #
143
+ # Product.create! # => raises an ActiveRecord::RecordNotSaved
136
144
class RecordNotSaved < ActiveRecordError
137
145
attr_reader :record
138
146
@@ -143,15 +151,17 @@ def initialize(message = nil, record = nil)
143
151
end
144
152
145
153
# Raised by {ActiveRecord::Base#destroy!}[rdoc-ref:Persistence#destroy!]
146
- # when a call to {#destroy}[rdoc-ref:Persistence#destroy]
147
- # would return false.
154
+ # when a record cannot be destroyed due to any of the
155
+ # <tt>before_destroy</tt> callbacks throwing +:abort+. See
156
+ # ActiveRecord::Callbacks for further details.
148
157
#
149
- # begin
150
- # complex_operation_that_internally_calls_destroy!
151
- # rescue ActiveRecord::RecordNotDestroyed => invalid
152
- # puts invalid.record.errors
158
+ # class User < ActiveRecord::Base
159
+ # before_destroy do
160
+ # throw :abort if still_active?
161
+ # end
153
162
# end
154
163
#
164
+ # User.first.destroy! # => raises an ActiveRecord::RecordNotDestroyed
155
165
class RecordNotDestroyed < ActiveRecordError
156
166
attr_reader :record
157
167
0 commit comments