aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/errors.rb
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-10-20 22:20:01 -0200
committerCarl Lerche <carllerche@mac.com>2009-10-20 17:52:32 -0700
commite714b499cc1f7ebc84f8d0e96607b79e60f2828d (patch)
treea9725eb2101a56db366603ca849a3ed260b710d6 /activemodel/lib/active_model/errors.rb
parent4f6d6f7031a88b647814fc0154e6b69b636dc912 (diff)
downloadrails-e714b499cc1f7ebc84f8d0e96607b79e60f2828d.tar.gz
rails-e714b499cc1f7ebc84f8d0e96607b79e60f2828d.tar.bz2
rails-e714b499cc1f7ebc84f8d0e96607b79e60f2828d.zip
Move validator, human_name and human_attribute_name to ActiveModel, remove deprecated error messages and add i18n_scope and lookup_ancestors.
Signed-off-by: Carl Lerche <carllerche@mac.com>
Diffstat (limited to 'activemodel/lib/active_model/errors.rb')
-rw-r--r--activemodel/lib/active_model/errors.rb19
1 files changed, 9 insertions, 10 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb
index 7a48960f89..e8bb62953d 100644
--- a/activemodel/lib/active_model/errors.rb
+++ b/activemodel/lib/active_model/errors.rb
@@ -93,7 +93,7 @@ module ActiveModel
# company = Company.create(:address => '123 First St.')
# company.errors.full_messages # =>
# ["Name is too short (minimum is 5 characters)", "Name can't be blank", "Address can't be blank"]
- def full_messages(options = {})
+ def full_messages
full_messages = []
each do |attribute, messages|
@@ -103,8 +103,10 @@ module ActiveModel
if attribute == :base
messages.each {|m| full_messages << m }
else
- attr_name = attribute.to_s.humanize
- prefix = attr_name + I18n.t('activemodel.errors.format.separator', :default => ' ')
+ attr_name = @base.class.human_attribute_name(attribute)
+ options = { :default => ' ', :scope => @base.class.i18n_scope }
+ prefix = attr_name + I18n.t(:"errors.format.separator", options)
+
messages.each do |m|
full_messages << "#{prefix}#{m}"
end
@@ -135,10 +137,7 @@ module ActiveModel
def generate_message(attribute, message = :invalid, options = {})
message, options[:default] = options[:default], message if options[:default].is_a?(Symbol)
- klass_ancestors = [@base.class]
- klass_ancestors += @base.class.ancestors.reject {|x| x.is_a?(Module)}
-
- defaults = klass_ancestors.map do |klass|
+ defaults = @base.class.lookup_ancestors.map do |klass|
[ :"models.#{klass.name.underscore}.attributes.#{attribute}.#{message}",
:"models.#{klass.name.underscore}.#{message}" ]
end
@@ -150,10 +149,10 @@ module ActiveModel
value = @base.send(:read_attribute_for_validation, attribute)
options = { :default => defaults,
- :model => @base.class.name.humanize,
- :attribute => attribute.to_s.humanize,
+ :model => @base.class.model_name.human,
+ :attribute => @base.class.human_attribute_name(attribute),
:value => value,
- :scope => [:activemodel, :errors]
+ :scope => [@base.class.i18n_scope, :errors]
}.merge(options)
I18n.translate(key, options)