Skip to content

Instantly share code, notes, and snippets.

@markoh
Created December 1, 2011 18:48
Show Gist options
  • Select an option

  • Save markoh/1418917 to your computer and use it in GitHub Desktop.

Select an option

Save markoh/1418917 to your computer and use it in GitHub Desktop.

Revisions

  1. markoh created this gist Dec 1, 2011.
    24 changes: 24 additions & 0 deletions gistfile1.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@

    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