Question

I use carmen-rails in my form to show country and sub-regions for each country, the first time when i select a country it update the list of subregions as well, then when i save these informations in database and go for the second time to above page and select another country it doesn't update the list of subregions !! then if reload page it does ! this is my js file in coffee-script format :

$ ->
  $('select#user_detail_attributes_country_code').change (event) ->

     select_wrapper = $('#user_detail_attributes_state_code')

     $('select', select_wrapper).attr('disabled', true)

     country_code = $(this).val()

     url = "/orders/subregion_options?parent_region=#{country_code}"
     select_wrapper.load(url)

note : I'm using rails 4, does rails 4 do some caching automatically and don't update the list ? or there is a problem with change method in jquery ? i can't find the problem here, any help please

my orders controller juste render a partial :

class OrdersController < ApplicationController

  def subregion_options
    render partial: 'orders/subregion_select'
  end

end

subregion partial code is :

div#order_state_code_wrapper
  - detail ||= params[:detail]
  - parent_region ||= params[:parent_region]
  - country = Carmen::Country.coded(parent_region) unless parent_region.nil?
  - if country.nil?
    %em Please select a country above
  - elsif country.subregions?
    = label_tag :user_detail_attributes_state_code, "State"
    = subregion_select_tag("user[detail_attributes][state_code]", detail.try(:state_code), parent_region)
  - else
    = label_tag :user_detail_attributes_state_code, "State"
    = text_field_tag("user[detail_attributes][state_code]", detail.try(:state_code))

Edit

i added alert("foo") inside jquery's change method, and when i select a country , sometimes it alert me "foo" and sometimes don't work !

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top