title: Rails 3 - Category Filter Using Select - Load Partial Via Ajax
body: <p>I am trying to filter Client Comments by using a select and rendering it in a partial. Right now the partial loads @client.comments. I have a Category model with a Categorizations join. This all works, just need to know how to get the select to call the filter action and load the partial with ajax. Thanks for you help.</p>
  
  <p>Categories controller:</p>
  
  <pre><code>def filter_category
      @categories = Category.all
  
      respond_to do |format|
        format.js # filter.rjs
      end    
  end
  </code></pre>
  
  <p>filter.js.erb:</p>
  
  <pre><code>page.replace_html 'client-note-inner', 
                    :partial =&gt; 'comments', 
                    :locals =&gt; { :com =&gt; Category.first.comments }
  </code></pre>
  
  <p>show.html.erb (clients)</p>
  
  <pre><code>&lt;% form_tag(filter_category_path(:id), :method =&gt; :put, :class =&gt; 'categories', :remote =&gt; true, :controller =&gt; 'categoires', :action =&gt; 'filter') do %&gt;
      &lt;label&gt;Categories&lt;/label&gt;
      &lt;%= select_tag(:category, options_for_select(Category.all.map {|category| [category.name, category.id]}, @category_id)) %&gt;
  &lt;% end %&gt;
  
  &lt;div class="client-note-inner"&gt;
      &lt;%= render :partial =&gt; 'comments', :locals =&gt; { :com =&gt; @comments } %&gt;
  &lt;/div&gt;&lt;!--end client-note-inner--&gt;
  </code></pre>
  
  <p>Hope that makes sense.
  Cheers.</p>