From 707b5c00abf98f1a383b96ad34313ff82d40758d Mon Sep 17 00:00:00 2001 From: Prathamesh Sonpatki Date: Sun, 1 May 2016 13:41:57 -0500 Subject: Active Model: Messages for strict validation always convert attributes to human readable form [ci skip] --- activemodel/lib/active_model/errors.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index d106f65fa2..87db8e2e19 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -310,9 +310,9 @@ module ActiveModel # :strict option can also be set to any other exception. # # person.errors.add(:name, :invalid, strict: true) - # # => ActiveModel::StrictValidationFailed: name is invalid + # # => ActiveModel::StrictValidationFailed: Name is invalid # person.errors.add(:name, :invalid, strict: NameIsInvalid) - # # => NameIsInvalid: name is invalid + # # => NameIsInvalid: Name is invalid # # person.errors.messages # => {} # -- cgit v1.2.3 From 25f829e43fbae0c29a3f2e54f5f0c7ebd7c9b46e Mon Sep 17 00:00:00 2001 From: Vipul A M Date: Mon, 2 May 2016 03:08:59 +0530 Subject: Add example for UnknownAttributeError [ci skip] --- activemodel/lib/active_model/errors.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activemodel') diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 87db8e2e19..c0f1bb084a 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -527,6 +527,15 @@ module ActiveModel end # Raised when unknown attributes are supplied via mass assignment. + # + # class Person + # include ActiveModel::AttributeAssignment + # include ActiveModel::Validations + # end + # + # person = Person.new + # person.assign_attributes(name: 'Gorby') + # # => ActiveModel::UnknownAttributeError: unknown attribute 'name' for Person. class UnknownAttributeError < NoMethodError attr_reader :record, :attribute -- cgit v1.2.3