пятница, июня 02, 2006

Pagination/Sorting/Filtering Automation

After reading "Nested with_scope" post I thought that it would be handy way to create entity lists with sorting, pagination and filtering features.

You could setup an around filter that would automatically paginate and filter your model entities.

class MyController < ApplicationController
around_filter SearchFilter.new(:products, :search_string), :only => :list
around_filter PagintationFilter.new(:products, 20), :only => :list

def list
@products = Product.find(:all)

Those could be wrapped in some kind of DSL (class methods).

The problem with similar sorting filter is that AR::Base::with_scope doesn't allow :order param.