Rails Simple Form Country Select

I am trying to create an application with Rails and Simple Form with country selection.

I get an error message:

wrong number of arguments (4 for 0) 

I am using the example that I found for a simple form on the gem page select page. I do not understand what is going wrong.

In my model, I have:

  geocoded_by :address after_validation :geocode, if: ->(obj){ @obj.address.present? and @obj.address_changed? } def address [city, state, participation_country].compact.join(', ') end 

In my form, I have:

  <%= f.simple_fields_for :scope do |participants_s| %> <%= participants_s.simple_fields_for :participant do |par| %> <%= par.select :participation_country, priority: ["AU", "GB", "NZ", "US"], selected: :participation_country, label: false, prompt: "Select participation country" %> 

I get the same error when I use

 <%= par.input :participation_country, 

In my opinion, I have:

 <%= @project.scope.participant.address %> 

Can anyone understand what I did wrong trying to fix this? The error message indicates the problem line:

 <%= par.select :participation_country, 

I cannot count 4 from anything other than the proposed country codes, although I deleted one of them to try and I get the same error.

When I try:

  <%= par.country_select("participation_country", {:prompt => "Choose Country"})%> 

I get the same error: wrong number of arguments (4 for 0)

I also tried to remove the gem to select the country and set the country_select gem instead. The hint for using a country_select pearl with a simple shape has the following example:

 country_select("user", "country", only: ["GB", "FR", "DE"]) 

However, the sample application for a simple form shows this as:

  <fieldset> <legend>With Only Chosen Countries</legend> <%= f.input :country_code, only: ["LV","SG"] %> <code>f.input :country_code, only: ["LV","SG"]</code> 

When I try to run an example application, as well as leadership styles, I get errors that methods do not recognize.

+7
ruby-on-rails simple-form
source share
4 answers

I finally got this job. I removed the gem to select the country (which is recommended for use with a simple form) and replaced it with the country_select stone. Wikis for this gem do not use the syntax corresponding to the sample wiki-related application.

This line worked for me:

 <%= par.input :participant_country, priority: ["AU", "NZ", "GB", "US"], label: false %> 
+8
source share

It should be:

 <%= par.input :participation_country, as: :country, priority_countries: ["AU", "GB", "NZ", "US"], label: false, prompt: "Select participation country" %> 

You do not need to specify the selected option, the form creator will do it for you.

Literature:

https://github.com/stefanpenner/country_select#usage

How to list all countries in a selection using country_select gem with simple_form

+1
source share

Try the code below

 <%= par.input :participation_country, as: :country, { priority_countries: ["AU", "GB", "NZ", "US"], selected: :participation_country }, { label: false, prompt: "Select participation country" } %> 

Link: See the "Providing Additional html Components" section of country_select .

+1
source share

Change par.select to f.input

 <%= f.simple_fields_for :scope do |participants_s| %> <%= participants_s.simple_fields_for :participant do |par| %> <%= f.input :participation_country, as: :country, { priority_countries: ["AU", "GB", "NZ", "US"], selected: :participation_country }, { label: false, prompt: "Select participation country" } %> 

Link :

See the โ€œ Wrap-Up Form Helpersโ€ section of the Readme simple_form .

+1
source share

All Articles