Rails Simple_Form:如何显示国家的长名称

我使用simple_form gem来选择国家:

 = simple_form_for @shop, :url => { :action => "create" }, :html => {:id => 'new_shop' } do |f| = f.simple_fields_for :address, :html => {:multipart => true} do |o| = o.input :country, :label => "Country" 

但是国家的名称在数据库中以短格式保存(如RUFRAU等)。

我想知道,我怎样才能在观点中展示这个国家的完整长名? 谢谢!

实际上,将国家代码保存在数据库中(不是长名称)是一个好主意,因为I18n。 拥有代码后,您可以获得如下名称:

 class User < ActiveRecord::Base # Assuming country_select is used with User attribute `country_code` # This will attempt to translate the country name and use the default # (usually English) name if no translation is available def country_name country = ISO3166::Country[country_code] country.translations[I18n.locale.to_s] || country.name end end 

检查: country_select:从国家/地区获取国家/地区名称