Skip to content

Instantly share code, notes, and snippets.

@chrislerum
Last active August 29, 2015 14:14
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 chrislerum/fc19876278945f5ac8f0 to your computer and use it in GitHub Desktop.
Save chrislerum/fc19876278945f5ac8f0 to your computer and use it in GitHub Desktop.
search snippet
20 @all_products.each do |i|
21 if (i.description.include? params[:query]) || (i.name.include? params[:query])
22 @products << i
23 end
24 end
#is this better?:
21 @products = all_products.reject do |i|
22 (!i.description.include? params[:query]) && (!i.name.include? params[:query])
23 end
#or a one liner:
20 @products = all_products.reject {|i| (!i.description.include? params[:query]) && (!i.name.include? params[:query])}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment