Created
May 6, 2010 11:47
-
-
Save bguthrie/392041 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gem idea, extracted from ResourceFull. Thoughts on the API? | |
class User < ActiveRecord::Base | |
named_scope :born_after, lambda {|date| | |
{ :conditions => ["birthdate >= ?", Date.parse(date)] } | |
} | |
query_set :filter do | |
filter_with_scope :active | |
queryable_with :email | |
queryable_with :born_after, :scope => :born_after | |
end | |
query_set :search do | |
queryable_with :first_name, :last_name, :fuzzy => true | |
queryable_with :username, :column => :email, :fuzzy => true | |
end | |
end | |
User.filter | |
#=> User.active | |
User.filter(:email => "[email protected]") | |
#=> User.active.scoped(:conditions => { :email => "[email protected]" }) | |
User.filter(:born_after => "04/03/2010", :email => "[email protected]") | |
#=> User.active.born_after("04/03/2010").scoped(:conditions => { :email => "[email protected]" }) | |
User.search(:first_name => "Guy", :last_name => "Three") | |
#=> User.scoped(:conditions => { :first_name => "%Guy%" }).scoped(:conditions => { :last_name => "%Three%" }) | |
User.search(:username => "gthree") | |
#=> User.scoped(:conditions => { :email => "%gthree%"}) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
or just use searchlogic -> http://github.com/binarylogic/searchlogic
User.search(:awesome => true)