0

Am trying to do filtering part. Filtering means, when user selects some choices based on that product details will be displayed. If user selects women (department) and men department it should display all the products which belongs to both women and men. To do this I am concatenating two objects. It is working fine. But when am trying to do pagination then it is throwing an error like:

undefined method `current_page' for Array

I want to concatenate two ActiveRecord objects and result should be in object of same active record only. Please tell me how to do this.

Now what am trying is:

@products += @prods

EDIT

deptids=["1" "2"]
deptids.each do |did|
    @prods=ProductDetail.where("department_id=?",did)
    if !(@products.nil?)
        @products += @prods
    else
        @products=@prods
    end
end
web spider26
  • 252
  • 4
  • 16

1 Answers1

0

After Googling i came to know that problem is in pagination since am getting undefined method current_page for Array. Therefore I used kaminari paginate array for pagination and my problem is fixed. For Kaminari paginate array i refered this stackoverflow link.

I have changed my code like this:

def index
    count=ProductDetail.count
    deptids=["1" "2"]
    deptids.each do |did|
        @search_res=ProductDetail.search do
            with :department_id, did    
            paginate :page=>1, :per_page=>count
        end
    end
    if !(@products.nil?)
        unless @products.kind_of?(Array)
          @products = @products.page(params[:page]).per(30)
        else
          @products = Kaminari.paginate_array(@products).page(params[:page]).per(30)
        end
    end
end
Community
  • 1
  • 1
web spider26
  • 252
  • 4
  • 16