I’m using will_paginate for pagination in a Rails 3 site. I’d like to be able to click on the table headers (e.g. “name”, “created at”) for each of the output fields and have the results ordered on that field. It would also be nice to be able to click again for reverse ordering. Is there something that works well with will_paginate for ordering? Can I do this just using will_paginate?
The table format I’m using is pretty generic:
<%= will_paginate %>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Updated</th>
</tr>
<% @shops.each do |shop| %>
<tr>
<td><%= shop.id %></td>
<td><%= shop.name %></td>
<td><%= shop.updated_at.strftime("%a %b %d %H:%M ") %></td>
</tr>
<% end %>
</table>
<%= will_paginate %>
You’ll find all you expect illustrated here: http://railscasts.com/episodes/240-search-sort-paginate-with-ajax