Skip to content

Instantly share code, notes, and snippets.

@markoh
Created December 1, 2011 18:48
Show Gist options
  • Save markoh/1418917 to your computer and use it in GitHub Desktop.
Save markoh/1418917 to your computer and use it in GitHub Desktop.
def self.search_filter(name,manufacture_id,product_type_id)
f_name = "'%#{name}%'"
f_manufacture_id = manufacture_id
f_manufacture_id = f_manufacture_id.join(', ') unless manufacture_id.nil?
f_product_type_id = "'#{product_type_id}'"
conditions = ["'1'='1'"]
conditions << "name LIKE #{f_name}" unless name.empty?
conditions << "manufacture_id IN (#{f_manufacture_id})"# unless manufacture_id.nil?
conditions << "product_type_id = #{f_product_type_id}" unless product_type_id.blank?
#where("name LIKE ?", f_name).where(:manufacture_id => [manufacture_ids])
cond2 = conditions.join ' and '
# if f_name.nil? #and manufacture_id.nil? and product_type_id.blank?
# find(:all)
# else
find(:all, :conditions => cond2, :order => 'id desc')
# end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment