Fork me on GitHub

The current version of Record Filter is now 0.9.8. If you are using a previous version, see this post for upgrade instructions.

Record Filter gives you the full power of ActiveRecord's query building tools with a heaping helping of DSL thrown in to save your Ruby-loving fingers from writing nasty SQL.

Blog.filter do
  any_of do
    having(:posts) do
      with(:permalink, nil)
      having(:comments).with(:offensive, true)

Record Filter also supports named filters, which work much like named scopes and are even compatible with them. The syntax for using named filters is exactly the same as for creating filters on the fly.

class Post < ActiveRecord::Base
  named_scope :with_permalink, lambda { |value| 
    { :conditions => { :permalink => value } } 
  named_filter(:with_content) { |value| with(:content, value) }
  named_filter(:created_recently) { with(:created_at).greater_than( }


Record Filter supports all of the following SQL-stomping features:

For further documentation, check out the project page for a getting-started guide with plenty of examples or take a peek the RDocs for all the gory details.

Get It

$ sudo gem install aub-record_filter --source=

In Rails, you'll need to add this to your environment.rb file:

config.gem 'aub-record_filter', :lib => 'record_filter', :source => ''