From e45208a394c4960f54dfd2ea81edf184d6c252d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A9?= Date: Wed, 29 Sep 2021 16:56:49 +0200 Subject: [PATCH] refacto --- app/controllers/admin/p_product_refs_controller.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/app/controllers/admin/p_product_refs_controller.rb b/app/controllers/admin/p_product_refs_controller.rb index 641f43b..c187e7f 100644 --- a/app/controllers/admin/p_product_refs_controller.rb +++ b/app/controllers/admin/p_product_refs_controller.rb @@ -18,9 +18,7 @@ class Admin::PProductRefsController < ApplicationController # @purchase_p_product_cats = PProductCat.where(:purchase => true).order(:name).all - global_search_ids = @p_product_refs.ids - p_product_ref_cat_id_ids = @p_product_refs.ids - s_brand_id_ids = @p_product_refs.ids + global_search_ids = p_product_ref_cat_id_ids = s_brand_id_ids = @p_product_refs.ids if params[:search][:global].to_s != "" global_search_ids = PProductRef.global_search(params[:search][:global]).ids @@ -52,13 +50,11 @@ class Admin::PProductRefsController < ApplicationController s_brand_id_ids = @p_product_refs.where(:p_products => {:s_brand_id => params[:search][:s_brand_id]}).ids end + final_ids = global_search_ids & p_product_ref_cat_id_ids & s_brand_id_ids - if params[:search].present? - @p_product_refs = PProductRef.where(id: final_ids) - else - @p_product_refs = PProductRef.joins(:p_product) - end + @p_product_refs = PProductRef.where(id: final_ids) + @p_product_refs = sort_by_sorting(@p_product_refs, "id DESC") respond_to do |format|