0

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

Alfabravo
  • 7,493
  • 6
  • 46
  • 82
  • You have to use AJAX (Asynchronous JavaScript and XML) to send a request from the view (client) with the user_id in the params to the server, and then the server responds with a JSON object which contains the list of the associated objects – MrYoshiji Jul 31 '13 at 19:35

1 Answers1

0

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

gregates
  • 6,607
  • 1
  • 31
  • 31