roo*_*uby 8 ruby-on-rails internationalization rails-i18n
我有一个名为Role的模型.我在表格中使用下面的助手.有没有办法将name属性的值更改为另一种语言?
<%= f.collection_select :role_id, Role.all, :id, name, {} -%>
Run Code Online (Sandbox Code Playgroud)
区域设置/ de.yml
de:
role:
admin: "something"
editor: "something something"
Run Code Online (Sandbox Code Playgroud)
jim*_*orm 25
在模型中:
class Role < ActiveRecord::Base
def translated_name
I18n.t(name, :scope => 'role')
end
end
Run Code Online (Sandbox Code Playgroud)
在视图中:
<%= f.collection_select :role_id, Role.all, :id, :translated_name -%>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3859 次 |
| 最近记录: |