What i understand
Suppose I have a class with convenient validation, for example:
User < ActiveRecord::Base
validates :username, :format => {/regex/}, :message => :name_format
end
In this case, I can use i18nto make the error message translated by including the following in mine /config/locals/en.yml:
en:
activerecord:
errors:
models:
user:
attributes:
username:
name_format: 'has the way-wrong format, bro!'
This is normal and generally very convenient.
What I want to know:
My question is: what happens when I have subclasses inheriting from the user:
UserSubclassOne < User
end
UserSubclassTwo < User
end
...
UserSubclassEnn < User
end
Now the problem is that Rails cannot find the translation user_subclass_one.attributes.username.name_format.
He complains:
translation missing:
en.activerecord.errors.models.user_subclass_one.attributes.username.name_format
I hope that Rails will look up the hierarchy UserSubclassOnebefore Userwhen searching for the string in en.yml, and then notice when it gets a βhitβ, but (if I didnβt do something terribly wrong), apparently this does not happen.
en.yml.en.errors.models User, user_subclass_one, user_subclass_two .., Rails , .
, ?
:
User gem MyGem, Rails MyEngine, Rails MyApp, UserSubclassOne,..., UserSubclassEnn, , , MyGem::User, en.yml, - , , .
/:
, , . , MyApp ( UserSubclassOne) MyGem ( User). , User MyGem ( ), User :
User < ActiveRecord::Base
MyGem::User < ActiveRecord::Base
.
i18n , my_gem/user, User, my_gem.user, my_gem: user ..
, en.yml :
/config/locals/en.yml:
en:
activerecord:
errors:
models:
my_gem/user:
attributes:
username:
name_format: 'has the way-wrong format, bro!'
!