undefined method `paginate' for #<Array:0x0000000764d1b8>

Aravind picture Aravind · Oct 5, 2013 · Viewed 10.8k times · Source

This my code in the index controller.

order_customs = Order.select{|order| order.performer.white_label_id==1}
@orders_customs_display=order_customs.paginate(:page => params[:page], :per_page => 5)     
@orders_customs_refunded=order_customs.select{|order| order.refunded==true}.paginate(:page => params[:page], :per_page => 5)
order_white_label=Order.select{|order| order.performer.white_label_id!=1}
@orders_white_label_display=order_white_label.paginate(:page => params[:page], :per_page => 5)
@orders_white_label_refunded=order_white_label.select{|order| order.refunded==true}.paginate(:page => params[:page], :per_page => 5)      

I am using will_paginate gem for pagination. I was using it before without any error but when I changed the code from Order.all.paginate() to Order.select{}.paginate() error is coming.

The error I am getting is

undefined method `paginate'

I need to paginate those values for showing them in a table. If I can't paginate them, is there a workaround?

Answer

Tyler picture Tyler · Oct 5, 2013

You need to include the will_paginate method for the data type Array.

To do so, include the line

require 'will_paginate/array'

at the top of your controller, or in the ApplicationController if you need pagination in all of your controllers.