I am using Rails 5 and Bootstrap wth single_forn.
I am able to select the country correctly.
But when I am trying to select a state or a city I am getting only "Toshkent Shari" from Uzbekistan and no city no matter which country I selected.
It may be the case I an not using the right paratemetes in the form to be used by the two scripts I developed based on the models shown in this blog.
He are my application relevant files.
application_controller.rb
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
def index
end
def states
render json: CS.states(params[:country]).to_json
end
def cities
render json: CS.cities(params[:state], params[:country]).to_json
end
end
routes.rb
Rails.application.routes.draw do
resources :contacts
root to: "application#index"
get 'states/:country', to: 'application#states'
get 'cities/:state', to: 'application#cities'
end
_form.rb
<%= simple_form_for(@contact) do |f| %>
<%= f.error_notification %>
I am using Rails 5 and Bootstrap wth single_forn. I am able to select the country correctly. But when I am trying to select a state or a city I am getting only "Toshkent Shari" from Uzbekistan and no city no matter which country I selected. It may be the case I an not using the right paratemetes in the form to be used by the two scripts I developed based on the models shown in this blog. He are my application relevant files.
application_controller.rb
class ApplicationController < ActionController::Base protect_from_forgery with: :exception def index end def states render json: CS.states(params[:country]).to_json end def cities render json: CS.cities(params[:state], params[:country]).to_json end end
routes.rb
Rails.application.routes.draw do resources :contacts root to: "application#index"
get 'states/:country', to: 'application#states' get 'cities/:state', to: 'application#cities' end
_form.rb
<%= simple_form_for(@contact) do |f| %> <%= f.error_notification %>
<% end %>
Due to the use of the simple_form the IDs of the elements in the DOM are "contact_country", "contact_state" and "contact_city"
Any help to fix this is much appreciated.