开发者

How to localize activerecord model value with Rails 3

开发者 https://www.devze.com 2023-02-27 00:49 出处:网络
I want to localize model values within form helpers. For ex开发者_Python百科ample I have 2 models, Role and User, defined by the relation : role has_many users.

I want to localize model values within form helpers.

For ex开发者_Python百科ample I have 2 models, Role and User, defined by the relation : role has_many users.

To create a new user I have in my controller something like this :

@user = User.new
@roles = Role.all # role title return values "admin" or "customer" only

And in my form I have something like this :

f.collection_select :role_id, @roles, :id, :title, {:selected => (@user.role)}

How can I localize role title values?

I used to set my localization in config/locales files. Can I set activerecord model values in this way?

Thank you for your help!

Jeremy.


Globalize2 is one solution for data i18n. I've not used it though, so don't ask me if it eats your wife.

0

精彩评论

暂无评论...
验证码 换一张
取 消