gpt4 book ai didi

ruby-on-rails - i18n用于选择框

转载 作者:行者123 更新时间:2023-12-04 04:53:53 25 4
gpt4 key购买 nike

我有一个名为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

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

关于ruby-on-rails - i18n用于选择框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6683366/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com