This does not seem to load on my sidebar. I think it has something to do with Turbolinks in rails 4 since if I reload the page, it seems to work. Any idea on how to change this to get it working?
jQuery ->
  category = $('#subject_category').html()
  $('#subject_product').change ->
    product = $('#subject_product :selected').text()
    escaped_product = product.replace(/([ #;&,.+*~\':"!^$[\]()=>|\/@])/g, '\\$1')
    options = $(category).filter("optgroup[label='#{escaped_product}']").html()
    if options
      $('#subject_category').html(options)
      $('#subject_category').parent().show()
    else
      $('#subject_category').empty()
      $('#subject_category').parent().hide()
$ ->
  category = $('#sidebar .category_select').html()   
  options = $(category).filter("optgroup[label='Car']").html()
  if options
    $('#sidebar .category_select').html(options)
    $('#sidebar .category_select').parent().show()
  else
    $('#sidebar .category_select').empty()
    $('#sidebar .category_select').parent().hide()
 
    