diff --git a/app/controllers/admin/p_product_refs_controller.rb b/app/controllers/admin/p_product_refs_controller.rb index 4e0a2b7..2aa9872 100644 --- a/app/controllers/admin/p_product_refs_controller.rb +++ b/app/controllers/admin/p_product_refs_controller.rb @@ -139,31 +139,38 @@ class Admin::PProductRefsController < ApplicationController end def autocomplete - @p_product_refs = PProductRef.joins(:p_product).all - # @p_product_refs = PProductRef.for_search(params[:search]).limit(50) - - if params[:p_customer_id] - @p_customer = PCustomer.where(:id => params[:p_customer_id]).first - #@p_product_refs = @p_product_refs.where("p_products.p_customer_id IS NULL or p_products.p_customer_id = ? ", @p_customer.id).joins(:p_customer_cats).where(:p_customer_cats => {:id => @p_customer.p_customer_cat_id}) - end - - @p_product_refs = @p_product_refs.where(:p_products => {:enabled => true}) - - if params[:not_assembled].to_s == "true" - - @p_product_refs = @p_product_refs.not_assembleds - - end - + # @p_product_refs = PProductRef.joins(:p_product) + @p_product_refs = PProductRef.limit(10).global_search(params[:search]) + + + # @p_product_refs = PProductRef.joins(:p_product).all + # # @p_product_refs = PProductRef.for_search(params[:search]).limit(50) + + # if params[:p_customer_id] + # @p_customer = PCustomer.where(:id => params[:p_customer_id]).first + # #@p_product_refs = @p_product_refs.where("p_products.p_customer_id IS NULL or p_products.p_customer_id = ? ", @p_customer.id).joins(:p_customer_cats).where(:p_customer_cats => {:id => @p_customer.p_customer_cat_id}) + # end + + # @p_product_refs = @p_product_refs.where(:p_products => {:enabled => true}) + + # if params[:not_assembled].to_s == "true" + + # @p_product_refs = @p_product_refs.not_assembleds + + # end + result = [] - - - @p_product_refs.distinct.all.each do |p_product_ref| - result << {:member_label => p_product_ref.member_label, :id => p_product_ref.id } + + + # @p_product_refs.distinct.all.each do |p_product_ref| + # result << {:member_label => p_product_ref.member_label, :id => p_product_ref.id } + # end + + @p_product_refs.all.each do |p_product_ref| + result << {:member_label => p_product_ref.member_label, :id => p_product_ref.id } end - respond_to do |format| - format.json { render json: result} + format.json { render json: result} end end