Rails 3 - Category filter using selection - Loading partial access via Ajax

I am trying to filter out customer comments using selection and rendering it in a partial. Currently partial download @ client.comments. I have a category model with a merge of categories. It all works, you just need to know how to get the selection to invoke the filter action and load the partial with ajax. Thanks for the help.

Category controller:

def filter_category
    @categories = Category.all

    respond_to do |format|
      format.js # filter.rjs
    end    
end

      

filter.js.erb:

page.replace_html 'client-note-inner', 
                  :partial => 'comments', 
                  :locals => { :com => Category.first.comments }

      

show.html.erb (clients)

<% form_tag(filter_category_path(:id), :method => :put, :class => 'categories', :remote => true, :controller => 'categoires', :action => 'filter') do %>
    <label>Categories</label>
    <%= select_tag(:category, options_for_select(Category.all.map {|category| [category.name, category.id]}, @category_id)) %>
<% end %>

<div class="client-note-inner">
    <%= render :partial => 'comments', :locals => { :com => @comments } %>
</div><!--end client-note-inner-->

      

Hope this makes sense. Greetings.

+2


a source to share


1 answer


It's simple with simple onchange



<%= select_tag(:category, options_for_select(Category.all.map {|category| [category.name, category.id]}, @category_id), onchange => 'form.submit()') %>

      

+1


a source







All Articles