I have a model that connects to an ext开发者_开发百科ernal 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?
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
If you cannot avoid using find_by_sql, check out last question of kaminari wiki.
Looking at the kaminari plugin it seems to only apply to ActiveRecord and ActiveRecord scopes, but find_by_sql does not work as a scope, but rather returns an Array.
I haven't found, digging through kaminari, a transparent way to 'paginate' an array. You could try to roll it by hand, but it might be tricky.
精彩评论