0

I am using gem 'country_select', github: 'stefanpenner/country_select' in my gem file and in my form i have defined it like this:

<%= form_for(@account_detail) do |f| %>

  <div class="field">
    <%= f.label :city %><br>
    <%= f.text_field :city %>
  </div>
  <div class="field">
    <%= f.label :zip %><br>
    <%= f.number_field :zip %>
  </div>
  <div class="field">
    <%= f.label :first_name %><br>
    <%= f.text_field :first_name %>
  </div>
  <div class="field">
    <%= f.label :last_name %><br>
    <%= f.text_field :last_name %>
  </div>
  <div class="field">
    <%= f.label :country %><br>
    <%= f.country_select("account_detail", "country") %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>
<% end %>

on submit its giving error ActionView::Template::Error (wrong number of arguments (4 for 0)):

Which gem is best to show all countries?

Suhaib Janjua
  • 3,538
  • 16
  • 59
  • 73
Dinshaw Raje
  • 933
  • 1
  • 12
  • 33

3 Answers3

1

I would use:

<%= f.country_select :country %>

If you like to prioritize some countries in the select pass them in in an array:

 <%= f.country_select :country, {priority_countries: %w(<COUNTRY CODE i.e. US>), prompt: 'Select Country'} %>

You can add class: 'your-class' and id or whatever just as with any other field if you like. Hope it helps.

Thomas
  • 622
  • 5
  • 13
  • what version of the gem are you using? Try locking to `gem 'country_select', '~> 2.1.0'` or `2.2.0` Anyway, it works for me in rails 4.1.8/ruby 2.1.2 – Thomas Apr 07 '15 at 09:50
  • me having rails version4.1.0 and ruby 2.1.5p273 and gem 'country_select', '~> 2.1.0' still not working tried with 2.2.0 also but no improvement – Dinshaw Raje Apr 07 '15 at 10:06
  • Works when I change `gem 'country_selected'` for `gem 'country_select', '~> 2.1.0'`. Thank you, @Thomas. – monteirobrena Jul 21 '15 at 13:58
1

This should do!

<%= f.country_select :country, { priority_countries: ["GB", "US"], selected: "GB" } %>
Sylar
  • 11,422
  • 25
  • 93
  • 166
0

I have solved this issue by adding this method in my model:

def country_name
    country = ISO3166::Country[country_code]
    country.translations[I18n.locale.to_s] || country.name
  end

and in view change given line :

<%= f.country_select("account_detail", "country") %>

to this:

<%= f.country_select :country, format: :with_alpha2 %>

Hope this will help to someone else who will face this problem.

Dinshaw Raje
  • 933
  • 1
  • 12
  • 33