Skip to content

Instantly share code, notes, and snippets.

@goldnuggets24
Created January 16, 2015 14:26
Show Gist options
  • Save goldnuggets24/cc9feec349c32e416883 to your computer and use it in GitHub Desktop.
Save goldnuggets24/cc9feec349c32e416883 to your computer and use it in GitHub Desktop.
Get first 4 items returned from db where title matches searched criteria
@items += Item.where( "lower(title) ~* ?", "#{params[:s].downcase}".split(/,\s*/).map(&:strip).reject(&:empty?).first)
@items += Item.where( "lower(title) ~* ?", "#{params[:s].downcase}".split(/,\s*/).map(&:strip).reject(&:empty?).second)
@items += Item.where( "lower(title) ~* ?", "#{params[:s].downcase}".split(/,\s*/).map(&:strip).reject(&:empty?).third)
@items += Item.where( "lower(title) ~* ?", "#{params[:s].downcase}".split(/,\s*/).map(&:strip).reject(&:empty?).fourth)
@goldnuggets24
Copy link
Author

Just thought of something dumb... I guess (at the very least) I could probs make the first half of this statement a variable and re-use that way...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment