我正在使用卡门宝石渲染一个国家选择在Rails。国家作为代码存储在数据库中。我如何从这段代码中得到“全名”?
gem 'carmen-rails','~> 1.0.0.beta3‘
<%= f.country_select :country, prompt: 'Please select a country' %>我尝试了几种选择,但到目前为止都没有用!例如:
Carmen::country_name(@profile.country)导致错误:
用于Carmen的未定义方法`country_name‘:模块
第二次尝试:
在profiles_controller中:
@profile = Profile.find(params[:id])
@country = Carmen::Country.named( @profile.country ) 在概要索引视图中:
<%= @country.official_name %>这会导致错误:
用于nil:nil类的未定义方法`official_name‘
为什么我的申请失败了?
发布于 2012-07-28 01:18:57
发布于 2015-05-29 10:32:32
这是国名
@country = Carmen::Country.coded(@profile.country)
<%= @country.name %>还有国名
@subregions = @country.subregions
@state = @subregions.coded(@profile.state_code)
<%= @state.name %>希望这个答案是充分使用的。
https://stackoverflow.com/questions/11690462
复制相似问题