Ruby on rails i18n用于选择框
我有一个名为Role的模型。我正在以一种形式使用下面的助手。有没有办法将name属性的值更改为另一种语言Ruby on rails i18n用于选择框,ruby-on-rails,internationalization,rails-i18n,Ruby On Rails,Internationalization,Rails I18n,我有一个名为Role的模型。我正在以一种形式使用下面的助手。有没有办法将name属性的值更改为另一种语言 <%= f.collection_select :role_id, Role.all, :id, name, {} -%> 在模型中: class Role < ActiveRecord::Base def translated_name I18n.t(name, :scope => 'role') end end 类角色role) 结束 结束
<%= f.collection_select :role_id, Role.all, :id, name, {} -%>
在模型中:
class Role < ActiveRecord::Base
def translated_name
I18n.t(name, :scope => 'role')
end
end
类角色role)
结束
结束
他认为:
<%= f.collection_select :role_id, Role.all, :id, :translated_name -%>
<%= f.collection_select :role_id, Role.all, :id, :translated_name -%>