diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-30 13:07:48 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-30 13:12:12 +0100 |
commit | d6e2f5013cdc0aa830d167a84582f48dc636dc81 (patch) | |
tree | ff2f5726ad2a452a768fc551571ed3e09a80d1e6 /activemodel/lib/active_model | |
parent | 431fc3c81735f8873e52f4a1942a5ac761d18cc9 (diff) | |
download | rails-d6e2f5013cdc0aa830d167a84582f48dc636dc81.tar.gz rails-d6e2f5013cdc0aa830d167a84582f48dc636dc81.tar.bz2 rails-d6e2f5013cdc0aa830d167a84582f48dc636dc81.zip |
Drop AR I18n deprecation and simple use errors.messages as fallback.
Diffstat (limited to 'activemodel/lib/active_model')
-rw-r--r-- | activemodel/lib/active_model/errors.rb | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 2e5bcab070..ff11ddc605 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -133,28 +133,35 @@ module ActiveModel # <li><tt>activemodel.errors.models.admin.blank</tt></li> # <li><tt>activemodel.errors.models.user.attributes.title.blank</tt></li> # <li><tt>activemodel.errors.models.user.blank</tt></li> - # <li><tt>activemodel.errors.messages.blank</tt></li> # <li>any default you provided through the +options+ hash (in the activemodel.errors scope)</li> + # <li><tt>activemodel.errors.messages.blank</tt></li> + # <li><tt>errors.attributes.title.blank</tt></li> + # <li><tt>errors.messages.blank</tt></li> # </ol> def generate_message(attribute, message = :invalid, options = {}) message, options[:default] = options[:default], message if options[:default].is_a?(Symbol) defaults = @base.class.lookup_ancestors.map do |klass| - [ :"models.#{klass.name.underscore}.attributes.#{attribute}.#{message}", - :"models.#{klass.name.underscore}.#{message}" ] + [ :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.underscore}.attributes.#{attribute}.#{message}", + :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.underscore}.#{message}" ] end defaults << options.delete(:default) - defaults = defaults.compact.flatten << :"messages.#{message}" + defaults << :"#{@base.class.i18n_scope}.errors.messages.#{message}" + defaults << :"errors.attributes.#{attribute}.#{message}" + defaults << :"errors.messages.#{message}" + + defaults.compact! + defaults.flatten! key = defaults.shift value = @base.send(:read_attribute_for_validation, attribute) - options = { :default => defaults, + options = { + :default => defaults, :model => @base.class.model_name.human, :attribute => @base.class.human_attribute_name(attribute), - :value => value, - :scope => [:errors] + :value => value }.merge(options) I18n.translate(key, options) |