615-852-6559 615-852-6559

Blog

How to do a Rails search in multiple columns

19 January 2010

How do I find a search term in Rails that might be in several columns?
  named_scope :with_name_or_keyword, lambda { |*args| {:conditions => ["speakers.name like ? OR speakers.bio like ? OR speakers.tagline like ?", ("%#{args.first}%" || ""), ("%#{args.first}%" || ""), ("%#{args.first}%" || "")]} }
will work with something like this:
Speaker.with_name_or_keyword("Dave")

blog comments powered by Disqus