I have a question about paginating non-persisted data which is sourced from a remote http request to an API (or many).
My Rails 3 app sends a net/http request to a search engine API and receives a JSON object. I'm loading this into ruby and paginating the results in the view. The initial query receives 50 hits and Kaminari is displaying:
@items = Kaminari.paginate_array(array).page(params[:page]).per(10)
Now when I click for page 2 in the view, the controller executes the request for the JSON again rather than using the results in array
.
This code is in a helper method and that's a problem. I that realise moving the pagination code into the controller will make this possible. bing_search
returns @items
now.
if params[:bing]
@bing = bing_search(@query)
end
I need something like:
@items = Kaminari.paginate_array(@bing).page(params[:page]).per(10)
I am just wondering how I can persist the array
while paginating. I have just looked at caching and that looks promising but I don't know anything about how it works yet.