ruby-on-rails – 用于选择框的i18n
发布时间:2020-12-16 19:33:35 所属栏目:百科 来源:网络整理
导读:我有一个名为Role的模型.我在表格中使用下面的助手.有没有办法将name属性的值更改为另一种语言? %= f.collection_select :role_id,Role.all,:id,name,{} -% 区域设置/ de.yml de: role: admin: "something" editor: "something something" 解决方法 在模型
我有一个名为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,:translated_name -%> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |