aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-11-26 12:44:13 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-11-26 12:44:13 -0200
commitc5a711e28b65ee61f1e1cd333b09fba292773dd7 (patch)
tree792e7ab7a4c853b046827bea6ade8cc8d1d5c8e7
parent683b476b4521b023b652065592eb7518d2d481c4 (diff)
parent59190c037999d302dd95b1f53f7049c2cec3f7b9 (diff)
downloadrails-c5a711e28b65ee61f1e1cd333b09fba292773dd7.tar.gz
rails-c5a711e28b65ee61f1e1cd333b09fba292773dd7.tar.bz2
rails-c5a711e28b65ee61f1e1cd333b09fba292773dd7.zip
Merge pull request #17786 from recursive-madman/activerecord-errors-codestyle
Code style changes for various activerecord errors
-rw-r--r--activerecord/lib/active_record/errors.rb2
-rw-r--r--activerecord/lib/active_record/validations.rb7
2 files changed, 6 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/errors.rb b/activerecord/lib/active_record/errors.rb
index ca4fede7a2..14819aab54 100644
--- a/activerecord/lib/active_record/errors.rb
+++ b/activerecord/lib/active_record/errors.rb
@@ -196,6 +196,7 @@ module ActiveRecord
# offending attribute.
class AttributeAssignmentError < ActiveRecordError
attr_reader :exception, :attribute
+
def initialize(message, exception, attribute)
super(message)
@exception = exception
@@ -208,6 +209,7 @@ module ActiveRecord
# objects, each corresponding to the error while assigning to an attribute.
class MultiparameterAssignmentErrors < ActiveRecordError
attr_reader :errors
+
def initialize(errors)
@errors = errors
end
diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb
index 7f7d49cdb4..a6c8ff7f3a 100644
--- a/activerecord/lib/active_record/validations.rb
+++ b/activerecord/lib/active_record/validations.rb
@@ -5,13 +5,14 @@ module ActiveRecord
# +record+ method to retrieve the record which did not validate.
#
# begin
- # complex_operation_that_calls_save!_internally
+ # complex_operation_that_internally_calls_save!
# rescue ActiveRecord::RecordInvalid => invalid
# puts invalid.record.errors
# end
class RecordInvalid < ActiveRecordError
- attr_reader :record # :nodoc:
- def initialize(record) # :nodoc:
+ attr_reader :record
+
+ def initialize(record)
@record = record
errors = @record.errors.full_messages.join(", ")
super(I18n.t(:"#{@record.class.i18n_scope}.errors.messages.record_invalid", :errors => errors, :default => :"errors.messages.record_invalid"))