Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find_by_sql and pagination with kamanari

I have a model that connects to an external database and I query using the find_by_sql method like so:

External.find_by_sql("SELECT * from table")

However when I add the .page(params[:page]), the error "undefined method page for class array" appears. Is it possible to paginate the results fetched using find_by_sql?

like image 236
chourobin Avatar asked Dec 21 '22 15:12

chourobin


2 Answers

This worked for me:

Kaminari.paginate_array(my_array_object).page(params[:page]).per(10)

https://github.com/kaminari/kaminari/wiki/Kaminari-recipes#-how-do-i-paginate-an-array

like image 145
Jenn Avatar answered Dec 24 '22 05:12

Jenn


If you cannot avoid using find_by_sql, check out last question of kaminari wiki.

like image 34
methyl Avatar answered Dec 24 '22 04:12

methyl