title: How do I make a ajax search by collection_select in rails?
body: <p>I am trying to display cities by selecting a particular state. But I don't know how to make a ajax request with the data "selected option in collection_select". </p>
  
  <pre><code>form 
  
  %= form_for @college do |f| %&gt;
  &lt;div class="form-group"&gt;
  
      &lt;%= f.label "Select state"%&gt;
      &lt;%= f.collection_select(:state_id, @state, :id, :state,  {},  {class: "form-control", :id =&gt; "state_select"})%&gt;
  &lt;/div&gt;&lt;br&gt;
    &lt;div class="form-group"&gt;
      &lt;%= f.label :city_id, "Select city"%&gt;
      &lt;%= f.collection_select(:city_id, @city, :id, :city,  {},  {class: "form-control", :id =&gt; "city_select"})%&gt;
  &lt;/div&gt;&lt;br&gt;
  &lt;div class="form-group"&gt;
      &lt;%= f.label :college, "college Name"%&gt;
      &lt;%= f.text_field :college, class: "form-control", placeholder: "Enter college name", required: true%&gt;
      &lt;br&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
      &lt;%= f.submit class: "btn btn-primary"%&gt;
  
  &lt;/div&gt;
  &lt;% end %&gt;
  
   Controller for update
   def update_cities
   @cities = City.where("state_id = ?", params[:state_id])
   respond_to do |format|
    format.js
   end
   end
  
   JS incomplete
  
   $('#state_select').on('change', function(){
   $('#city_select').value.empty;
   })
  </code></pre>