Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails Simple Form Country Select

I am trying to make an app with Rails and Simple Form with country-select.

I am getting an error that says:

wrong number of arguments (4 for 0)

I am using the example that i found, for simple form on the country select gem documentation page. I don't understand what's 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 view I have:

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

Can anyone see what I have done wrong in trying to set this up? The error message indicates the problematic line is:

<%= par.select :participation_country,

I can't count 4 of anything except suggested country codes, although I deleted one of those 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 have also tried removing country-select gem and installing country_select gem instead. The guidance for using country_select gem with simple form has this example:

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

However the example applications for simple form show 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 following the example application as well as the guidance styles, I get errors that don't recognise methods.

like image 646
Mel Avatar asked Jun 27 '15 04:06

Mel


2 Answers

I finally got this working. I removed the country-select gem (which is recommended for use with simple form) and replaced it with the country_select gem. The wiki for this gem does not use syntax that matches the example application linked on the wiki.

This line ended up working for me:

<%= par.input :participant_country, priority: ["AU", "NZ", "GB", "US"], label: false %>
like image 151
Mel Avatar answered Sep 22 '22 00:09

Mel


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" } %>

Reference:

See Wrapping Rails Form Helpers section in the Readme of simple_form.

like image 37
Vamsi Krishna Avatar answered Sep 22 '22 00:09

Vamsi Krishna