Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails i18n用于选择框_Ruby On Rails_Internationalization_Rails I18n - Fatal编程技术网

Ruby on rails i18n用于选择框

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) 结束 结束

我有一个名为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, :translated_name -%>

<%= f.collection_select :role_id, Role.all, :id, :translated_name -%>