app/controllers/products_controller.rb
def filter_products(search)
      return Product.where(true) if search.blank?
      @group = search[:group]
      @name = search[:name]
      @product_state = search[:product_state]
      @product_type = search[:product_type]
      @product_priority = search[:product_priority]
      @dependency = search[:dependency].to_s
      @search_string = ""
      @search_array = ["true"]
      @search_array << "products.name LIKE '%#{@name}%'" unless @name.blank? 
      @search_array << "product_state_id = #{@product_state}" unless @product_state.blank?
      @search_array << "product_type_id = #{@product_type}" unless @product_type.blank? 
      @search_array << "product_priority_id = #{@product_priority}" unless @product_priority.blank? 
      @search_string = @search_array.join(" AND ")
      @products = Product.where(@search_string)
      @products = @products.joins(:groups).where("product_groups.group_id" => @group).uniq unless @group.blank?
      @products = @products.joins(:dependencies).uniq if @dependency == "true"
      @products = @products.where("products.id NOT IN (?)", @products.joins(:dependencies).pluck("products.id").uniq) if @dependency == "false"
      return @products
    end
# Filters the products displayed on the index page based on paramaters provided
Filters the products displayed on the index page based on paramaters provided
Filters the products displayed on the index page based on paramaters provided
def filter_products(search)
      return Product.where(true) if search.blank?
      @group = search[:group]
      @name = search[:name]
      @product_state = search[:product_state]
      @product_type = search[:product_type]
      @product_priority = search[:product_priority]
      @dependency = search[:dependency].to_s
      @search_string = ""
      @search_array = ["true"]
      @search_array << "products.name LIKE '%#{@name}%'" unless @name.blank? 
      @search_array << "product_state_id = #{@product_state}" unless @product_state.blank?
      @search_array << "product_type_id = #{@product_type}" unless @product_type.blank? 
      @search_array << "product_priority_id = #{@product_priority}" unless @product_priority.blank? 
      @search_string = @search_array.join(" AND ")
      @products = Product.where(@search_string)
      @products = @products.joins(:groups).where("product_groups.group_id" => @group).uniq unless @group.blank?
      @products = @products.joins(:dependencies).uniq if @dependency == "true"
      @products = @products.where("products.id NOT IN (?)", @products.joins(:dependencies).pluck("products.id").uniq) if @dependency == "false"
      return @products
    end
def filter_products ( search ) return Product . where ( true ) if search . blank? @group = search [ :group ] @name = search [ :name ] @product_state = search [ :product_state ] @product_type = search [ :product_type ] @product_priority = search [ :product_priority ] @dependency = search [ :dependency ] . to_s @search_string = "" @search_array = [ "true" ] @search_array << "products.name LIKE '%#{@name}%'" unless @name . blank? @search_array << "product_state_id = #{@product_state}" unless @product_state . blank? @search_array << "product_type_id = #{@product_type}" unless @product_type . blank? @search_array << "product_priority_id = #{@product_priority}" unless @product_priority . blank? @search_string = @search_array . join ( " AND " ) @products = Product . where ( @search_string ) @products = @products . joins ( :groups ) . where ( "product_groups.group_id" => @group ) . uniq unless @group . blank? @products = @products . joins ( :dependencies ) . uniq if @dependency == "true" @products = @products . where ( "products.id NOT IN (?)" , @products . joins ( :dependencies ) . pluck ( "products.id" ) . uniq ) if @dependency == "false" return @products end
Filters the products displayed on the index page based on paramaters provided
Filters the products displayed on the index page based on paramaters provided
search