0

I am currently working on a Rails application where I need to list countries and their corresponding states/provinces. For this function, I am using the Country-State-Select gem.

I have included the gem in my Gemfile

gem 'country_state_select'

And installed it

bundle install

However, the official documentation used simple_form objects while I am using the default rails form objects.

Here's my form field for country, which works very fine:

<%= form.label :country %>
<%= form.select :country_field, collection: CountryStateSelect.countries_collection %>

However, the form field for state which is below:

<%= form.label :state %>
<%= form.select :state_field, CountryStateSelect.state_options(form: form, field_names: { country: country_field, state: state_field } ) %>

keeps throwing errors:

undefined local variable or method `country_field'

Here's the simple form implementation of it in the Country-State-Select gem documentation, which I am trying to convert to the default rails form objects:

<%= options = { form: f, field_names: { :country => :country_field, :state => :state_field } } 
f.input :state_field, CountryStateSelect.state_options(options) %>
halfer
  • 19,824
  • 17
  • 99
  • 186
Promise Preston
  • 24,334
  • 12
  • 145
  • 143

1 Answers1

0

I just learnt from Arvind Vyas the owner of the Country-Select-Select gem in this Stack Overflow answer that the gem depends on the simple_form gem.

So the best bet is to integrate the simple_form gem into the application or look for other alternatives, since the default rails form which I am using will not work for the implementation.

halfer
  • 19,824
  • 17
  • 99
  • 186
Promise Preston
  • 24,334
  • 12
  • 145
  • 143