Skip to content

Instantly share code, notes, and snippets.

@tonywok
Created January 30, 2011 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tonywok/802531 to your computer and use it in GitHub Desktop.
Save tonywok/802531 to your computer and use it in GitHub Desktop.
simple search
scope :search, lambda { |keywords|
query = nil
table = arel_table
SEARCH_ATTRS.each do |attr|
if attr == SEARCH_ATTRS.first
query = table[attr].matches("%#{keywords}%")
else
query = query.or(table[attr].matches("%#{keywords}%"))
end
end; where(query)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment