Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 785
Aravind Avatar asked Oct 04 '13 23:10

Aravind


1 Answers

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.

like image 144
Tyler Avatar answered Nov 02 '22 19:11

Tyler