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

2

26

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?

Tahoe answered 4/10, 2013 at 23:51 Comment(0)
T
65

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.

Thriller answered 5/10, 2013 at 0:1 Comment(2)
The tricky thing is if you require it elsewhere in other controller and this one is called before the controller without require then no error is thrown. So don't forget to add it everywhere arrays are paginated or anywhere above e.g. ApplicationController.Stockist
This worked great, just make sure to use it outside the class definition if you are using these in your models.Cavalla
B
-2

Removing the .all worked for me.

Bedell answered 23/1, 2014 at 13:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.