country_select在show action上显示完整的国家/地区名称

Rue*_*gen -2 ruby forms gem ruby-on-rails

我使用gem'country_select'为我的rails应用程序选择一个表单的国家/地区,但是当我去show或index操作时,我会看到存储的值.有没有方法将值转换为国家/地区的全名字符串?

[AU] => "Australia"
Run Code Online (Sandbox Code Playgroud)

Kri*_*ján 6

该文档包括如何准确获取您想要的内容.

country = ISO3166::Country[country_code]
country.translations[I18n.locale.to_s] || country.name
Run Code Online (Sandbox Code Playgroud)

  • 这段代码不再起作用了。我尝试使用它,但出现错误“nil:NilClass 的未定义方法翻译” (2认同)