aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/errors.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activemodel/lib/active_model/errors.rb')
-rw-r--r--activemodel/lib/active_model/errors.rb26
1 files changed, 19 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 8326853879..e35ed03e74 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -3,6 +3,7 @@
require 'active_support/core_ext/array/conversions'
require 'active_support/core_ext/string/inflections'
require 'active_support/core_ext/object/deep_dup'
+require 'active_support/core_ext/string/filters'
module ActiveModel
# == Active \Model \Errors
@@ -33,11 +34,11 @@ module ActiveModel
# send(attr)
# end
#
- # def Person.human_attribute_name(attr, options = {})
+ # def self.human_attribute_name(attr, options = {})
# attr
# end
#
- # def Person.lookup_ancestors
+ # def self.lookup_ancestors
# [self]
# end
# end
@@ -123,9 +124,9 @@ module ActiveModel
# Set messages for +key+ to +value+.
#
- # person.errors.get(:name) # => ["cannot be nil"]
+ # person.errors[:name] # => ["cannot be nil"]
# person.errors.set(:name, ["can't be nil"])
- # person.errors.get(:name) # => ["can't be nil"]
+ # person.errors[:name] # => ["can't be nil"]
def set(key, value)
ActiveSupport::Deprecation.warn(<<-MESSAGE.squish)
ActiveModel::Errors#set is deprecated and will be removed in Rails 5.1.
@@ -138,12 +139,12 @@ module ActiveModel
# Delete messages for +key+. Returns the deleted messages.
#
- # person.errors.get(:name) # => ["cannot be nil"]
+ # person.errors[:name] # => ["cannot be nil"]
# person.errors.delete(:name) # => ["cannot be nil"]
- # person.errors.get(:name) # => []
+ # person.errors[:name] # => []
def delete(key)
- messages.delete(key)
details.delete(key)
+ messages.delete(key)
end
# When passed a symbol or a name of a method, returns an array of errors
@@ -524,4 +525,15 @@ module ActiveModel
# # => ActiveModel::StrictValidationFailed: Name can't be blank
class StrictValidationFailed < StandardError
end
+
+ # Raised when unknown attributes are supplied via mass assignment.
+ class UnknownAttributeError < NoMethodError
+ attr_reader :record, :attribute
+
+ def initialize(record, attribute)
+ @record = record
+ @attribute = attribute
+ super("unknown attribute '#{attribute}' for #{@record.class}.")
+ end
+ end
end