Skip to content

Instantly share code, notes, and snippets.

@Odaeus
Created March 19, 2009 22:07
Show Gist options
  • Save Odaeus/82092 to your computer and use it in GitHub Desktop.
Save Odaeus/82092 to your computer and use it in GitHub Desktop.
conds = {:name => params[:name], :cas_number => params[:cas_number]}.reject {|k,v| v.nil? }
conds = conds.inject([[]]) {|h,(k,v)| h.first << "#{k} LIKE ?"; h << "%#{v}%"; h }
conds[0] = conds[0].join(' AND ')
ingredients = Ingredient.find(:all, :conditions => conds)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment