app/controllers/portfolios_controller.rb
# Filters the portfolios displayed on the index page based on paramaters provided
Filters the portfolios displayed on the index page based on paramaters provided
Filters the portfolios displayed on the index page based on paramaters provided
def filter_portfolios(search)
      portfolios = Portfolio.where(true)
      return portfolios if search.blank?
      @group = search[:group]
      @product = search[:product]
      @name = search[:name]
      search_array = []
      search_array << "product_group_portfolios.group_id = #{@group}" unless @group.blank? 
      search_array << "product_group_portfolios.product_id = #{@product}" unless @product.blank? 
      search_string = search_array.join(" AND ")
      portfolios = portfolios.joins(:product_group_portfolios).uniq unless search_string.blank?
      portfolios = portfolios.where(search_string) unless search_string.blank?
      portfolios = portfolios.where("portfolios.name LIKE '%#{@name}%'") unless @name.blank?
      return portfolios
    end
def filter_portfolios ( search ) portfolios = Portfolio . where ( true ) return portfolios if search . blank? @group = search [ :group ] @product = search [ :product ] @name = search [ :name ] search_array = [ ] search_array << "product_group_portfolios.group_id = #{@group}" unless @group . blank? search_array << "product_group_portfolios.product_id = #{@product}" unless @product . blank? search_string = search_array . join ( " AND " ) portfolios = portfolios . joins ( :product_group_portfolios ) . uniq unless search_string . blank? portfolios = portfolios . where ( search_string ) unless search_string . blank? portfolios = portfolios . where ( "portfolios.name LIKE '%#{@name}%'" ) unless @name . blank? return portfolios end
Filters the portfolios displayed on the index page based on paramaters provided
Filters the portfolios displayed on the index page based on paramaters provided
search