diff --git a/activemodel/lib/active_model/errors.rb b/activemodel/lib/active_model/errors.rb index 1431228..626c8b0 100644 --- a/activemodel/lib/active_model/errors.rb +++ b/activemodel/lib/active_model/errors.rb @@ -289,8 +289,9 @@ module ActiveModel end defaults = @base.class.lookup_ancestors.map do |klass| - [ :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.underscore}.attributes.#{attribute}.#{type}", - :"#{@base.class.i18n_scope}.errors.models.#{klass.model_name.underscore}.#{type}" ] + model_scope = klass.model_name.underscore.gsub '/', '.' + [ :"#{@base.class.i18n_scope}.errors.models.#{model_scope}.attributes.#{attribute}.#{type}", + :"#{@base.class.i18n_scope}.errors.models.#{model_scope}.#{type}" ] end defaults << options.delete(:message) diff --git a/activemodel/test/cases/validations/i18n_validation_test.rb b/activemodel/test/cases/validations/i18n_validation_test.rb index e9f0e43..ce4b415 100644 --- a/activemodel/test/cases/validations/i18n_validation_test.rb +++ b/activemodel/test/cases/validations/i18n_validation_test.rb @@ -363,4 +363,17 @@ class I18nValidationTest < ActiveModel::TestCase assert_equal ["I am a custom error"], @person.errors[:title] end + # test class i18n scope with Module + + def test_model_with_module_i18n_scope + I18n.backend.store_translations 'en', :activemodel => {:errors => {:models => {:person_module => {:person => {:blank => 'generic blank'}}}}} + PersonModule::Person.validates_presence_of :title + person = PersonModule::Person.new :title => nil + person.valid? + assert_equal ['generic blank'], person.errors[:title] + + I18n.backend.store_translations 'en', :activemodel => {:errors => {:models => {:person_module => {:person => {:attributes => {:title => {:blank => 'title cannot be blank'}}}}}}} + person.valid? + assert_equal ['title cannot be blank'], person.errors[:title] + end end diff --git a/activemodel/test/models/person.rb b/activemodel/test/models/person.rb index cf16a38..eb84f7a 100644 --- a/activemodel/test/models/person.rb +++ b/activemodel/test/models/person.rb @@ -11,3 +11,8 @@ end class Child < Person end + +module PersonModule + class Person < ::Person + end +end