我有一个名为 Role 的模型。我正在表单中使用下面的助手。有没有办法将 name 属性的值更改为另一种语言?
<%= f.collection_select :role_id, Role.all, :id, name, {} -%>
语言环境/de.yml
de:
role:
admin: "something"
editor: "something something"
在模型中:
class Role < ActiveRecord::Base
def translated_name
I18n.t(name, :scope => 'role')
end
end
视图中:
<%= f.collection_select :role_id, Role.all, :id, :translated_name -%>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)