其他人有想法吗? 预先感谢您的帮助。 最佳答案 您应该使用I18n翻译-6ren">
gpt4 book ai didi

ruby-on-rails - 如何在选择 [Ruby on Rails] 的选项中将货币缩写 (EUR, USD) 更改为 (Euros, US Dollars)

转载 作者:行者123 更新时间:2023-12-02 22:17:46 25 4
gpt4 key购买 nike

如果输出是欧元、美元,如何更改(在 Rails 中)选择选项,.....我想要欧元、美元。

<%= select_tag('user[currency_id]', options_for_select(Currency.get_active.collect{|t| [t.name, t.id]}, @user.try(:currency_id) ), {:class => "bigselect"})  %>

其他人有想法吗?

预先感谢您的帮助。

最佳答案

您应该使用I18n翻译它们:

Currency.get_active.map{ |t| [I18n.t("currencies.names.long.#{t.name}"), t.id] }

在您的 locale.yml 中(en.yml 示例):

# en.yml
currencies:
names:
long:
usd: "US Dollars"
eur: "Euros"
#...
short:
usd: "$US"
eur: "€"

或者没有翻译系统的替代方案:

class Currency < ActiveRecord::Base
LONG_NAMES = {
'EUR' => 'Euros',
'USD' => 'US Dollars',
# ...
}
# ...
end

然后像这样使用它:

Currency.get_active.collect{ |t| [Currency.LONG_NAMES[t.name], t.id] }

如果 t.name 返回的条目不在 LONG_NAMES 常量中,则显示 t.name 属性:

Currency.get_active.collect{ |t| [Currency.LONG_NAMES[t.name] || t.name, t.id] }

关于ruby-on-rails - 如何在选择 [Ruby on Rails] 的选项中将货币缩写 (EUR, USD) 更改为 (Euros, US Dollars),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14198933/

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