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 using sunspot and concatenating two objects. It is working fine. But when am trying to do pagination using Kaminari it works fine if user selects only one department like women.

If user selects both men and women then it is throwing an error like:

undefined method `current_page' for Array

Am doing the above mentioned work like the following code.

deptids=["1" "2"]
deptids.each do |did|
    @search_res=ProductDetail.search do
        with :department_id, did                  
        paginate :page=>params[:page], :per_page=>15
    end
end

Please can any one tell that how to do pagination for array of objects using Kaminari Gem?

Please tell me how to do array of objects pagination using Kaminari or how to append two objects into one single object

web spider26
  • 252
  • 4
  • 16

1 Answers1

0

I solved this problem with the help of this Stackoverflow link.

The code what i have changed is in product_details controller

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.present?
        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

In view _index.html.erb

<%= paginate @products, :remote=>true %> 
Community
  • 1
  • 1
web spider26
  • 252
  • 4
  • 16