list_controls

Simple list filtering & sorting for Rails controller.

Plays nicely with SearchLogic.

Example

Controller:

class ProductsController < ApplicationController

enable_list_controls :default_filters => { 'state' => 'new' } 

def index
  @products = Product.all :conditions => { :state => @filters.state }
end

end

# Note: 
#
# Sort param stored in @filters.order, example 'ascend_by_title'
# Easy use with SearchLogic.

View:

<%= form_for :filters, @filters, :html => { :method => :get } do |f| %>
  <%= f.label :state %>
  <%= f.select :state, states_for_filter %>

<% end %>
</div>
<% for product in @products %>
  <tr>
    <td><%= product.id %></td>
    <td><%= product.title %></td>
    <td><%= product.state %></td>
  </tr>
<% end %>    
</table>

Copyright (c) 2009 Laurynas Butkus, released under the MIT license

<%= sort @filters, :by => :id %> <%= sort @filters, :by => :title, :as => t(:product_title) %> <%= sort @filters, :by => :state, :as => t(:state) %>