문제

I am using the Carmen gem to render a country select in Rails. The country is stored as Code in the database. How can I get the "Full name" back from this code?

gem 'carmen-rails', '~> 1.0.0.beta3'

<%= f.country_select :country, prompt: 'Please select a country' %>

I tried several options, none of them worked so far! For example:

Carmen::country_name(@profile.country)

Leading to error:

undefined method `country_name' for Carmen:Module

Second try:

in profiles_controller:

@profile = Profile.find(params[:id])
@country = Carmen::Country.named( @profile.country )  

In profiles index view:

<%= @country.official_name %>

This leads to error:

undefined method `official_name' for nil:NilClass

Why is my application failing?

도움이 되었습니까?

해결책

Check out the test spec for carmen on github:

https://github.com/jim/carmen/blob/master/spec/carmen/country_spec.rb

@country = Carmen::Country.coded(@profile.country)

<%= @country.name %>

다른 팁

This is for country name

@country = Carmen::Country.coded(@profile.country)

<%= @country.name %>

And for State Name

@subregions = @country.subregions
@state = @subregions.coded(@profile.state_code)
<%= @state.name %>

Hope this answer is use full.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top