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>
| <%= sort @filters, :by => :id %> | <%= sort @filters, :by => :title, :as => t(:product_title) %> | <%= sort @filters, :by => :state, :as => t(:state) %> |
|---|