title: Drop down filter to sort products by category on index page
body: <p>I am fairly new to rails and am building an online store. I currently have a products model and a categories model with the association: Products belong_to a category and a Category has_many products. I would like shoppers to have the ability to select a category in a drop down and the products on the index page will display only items in that category. </p>
  
  <p>I was able to get a drop down to show all of the categories using a form_tag but when I select on a category the index page does not filter to show just that category. </p>
  
  <p>Products index.html.erb:</p>
  
  <pre><code>&lt;%= form_tag('products', :remote =&gt; true) do %&gt;
    &lt;%= select_tag "category", options_from_collection_for_select(Category.all, "id", "name"),  { :include_blank =&gt; true , :class =&gt; "product_select"} %&gt;
    &lt;%= submit_tag 'Filter' %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>Products controller:</p>
  
  <pre><code>  def index
      if Product.all.collect == (params[:category])
          @products= Product.send(params[:category])   
      else
          @products = Product.order(:title)   
      end 
  
        respond_to do |format|
          format.html # index.html.erb
          format.js # index.js.erb
          format.json { render json: @products } 
        end  
    end
  </code></pre>
  
  <p>application.js:</p>
  
  <pre><code>$(document).ready -&gt;   $(".product_select").on "change", -&gt;
      $.ajax
        url: "/products"
        type: "GET"
        dataType: "script"
        data:
          dept_type: $(".product_select").val()
  </code></pre>
  
  <p>Thanks in advance for any help, let me know if any more information is needed. </p>