Find_by_sql and pagination with kamanari

I have a model that connects to an external database, and I request the find_by_sql method as follows:

External.find_by_sql ("SELECT * from table")

However, when I add .page (params [: page]), the error message "method page undefined for class array" appears. Is pagination of results possible with find_by_sql?

+4
source share
3 answers

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

+2
source

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

+9
source

A look at the kaminari plugin seems to apply only to the ActiveRecord and ActiveRecord realms, but find_by_sql doesn't work as a scope, but returns an array.

I did not find, digging through the fireplace, a transparent way to "split pages" into an array. You can try to collapse it manually, but it can be tricky.

0
source

Source: https://habr.com/ru/post/1347366/


All Articles