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) %>