diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-05-03 18:50:51 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-05-03 18:50:51 -0300 |
commit | a278668624209b2421634d3dc6ee82b6e0353546 (patch) | |
tree | 89c38c7a611495ea4895ad90a692e3c99e22b74b /activerecord/lib/active_record | |
parent | b6cc44bfa6b78f380503d3a4bc141bb529fd16bd (diff) | |
parent | ad5824bde0f63d5bb2e33b7fe86904d1fbd7ff95 (diff) | |
download | rails-a278668624209b2421634d3dc6ee82b6e0353546.tar.gz rails-a278668624209b2421634d3dc6ee82b6e0353546.tar.bz2 rails-a278668624209b2421634d3dc6ee82b6e0353546.zip |
Merge pull request #17824 from yuki24/change-record-not-saved-and-not-destroyed-to-include-error-msg
AR::RecordNotSaved & RecordNotDestroyed from save!/destroy! should include an error message
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r-- | activerecord/lib/active_record/errors.rb | 4 | ||||
-rw-r--r-- | activerecord/lib/active_record/persistence.rb | 4 |
2 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb index 98aee77557..0f1759abaa 100644 --- a/activerecord/lib/active_record/errors.rb +++ b/activerecord/lib/active_record/errors.rb @@ -71,9 +71,9 @@ module ActiveRecord class RecordNotDestroyed < ActiveRecordError attr_reader :record - def initialize(record) + def initialize(message, record = nil) @record = record - super() + super(message) end end diff --git a/activerecord/lib/active_record/persistence.rb b/activerecord/lib/active_record/persistence.rb index da8f4d027a..466175690e 100644 --- a/activerecord/lib/active_record/persistence.rb +++ b/activerecord/lib/active_record/persistence.rb @@ -148,7 +148,7 @@ module ActiveRecord # Attributes marked as readonly are silently ignored if the record is # being updated. def save!(*args) - create_or_update(*args) || raise(RecordNotSaved.new(nil, self)) + create_or_update(*args) || raise(RecordNotSaved.new("Failed to save the record", self)) end # Deletes the record in the database and freezes this instance to @@ -193,7 +193,7 @@ module ActiveRecord # and #destroy! raises ActiveRecord::RecordNotDestroyed. # See ActiveRecord::Callbacks for further details. def destroy! - destroy || raise(ActiveRecord::RecordNotDestroyed, self) + destroy || raise(RecordNotDestroyed.new("Failed to destroy the record", self)) end # Returns an instance of the specified +klass+ with the attributes of the |