Getting input from view to scope an index

62 Views Asked by At

So I am trying to add the ability to select a user in the view, and then return only the Lists that are associated with that user. I can do this for now hard coded in the controller.

  def show
   @some_lists = List.sort(:boolean => true, :user_id => 3)

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @some_list }
    end
end

But I want to be able to choose the user from the views

        <% @some_lists.each do |list| %>
      <tr>
        <td><%= list.id_name %></td>
        <td><%= list.day %></td>
        <td><%= list.start_time %></td>
        <td><%= list.end_time %></td>
      </tr>
    <% end %>

What is the best way to go about doing this, I also plan on adding the ability to sort by the list.start_time and list.end_time as well

1

There are 1 best solutions below

0
On

You'll definitely want to do this with AJAX. For the specific thing you want to do (filtering/sorting a table) there's a javascript plugin I would recommend:

DataTables

(you'll want to check out the documentation on server-side processing)

There's even a really nice tutorial to using it with rails in RailsCast #340