Skip to content

Instantly share code, notes, and snippets.

@yelvert
Created January 23, 2011 06:30
Show Gist options
  • Save yelvert/791876 to your computer and use it in GitHub Desktop.
Save yelvert/791876 to your computer and use it in GitHub Desktop.
Parameters: {"query"=>{"searchable_columns"=>["id", "name", "content", "test_1"], "search"=>"w"}}
x = []
query[:searchable_columns].each do |column|
x << Widget.arel_table[column.to_sym].matches("%#{query[:search]}%")
end
@widgets = Widget.where(x.inject(&:or))
Widget Load (2.5ms) SELECT "widgets".* FROM "widgets" WHERE (((("widgets"."id" LIKE 0 OR "widgets"."name" LIKE '%w%') OR "widgets"."content" LIKE '%w%') OR "widgets"."test_1" LIKE '%w%'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment