paginate last 20 models, ruby on rails (will_paginate gem)

I'm trying to do pagination using the will_paginate gem:

@books = Book.joins(:ads).last(20).page(params[:page]).per_page(10)

But I'm getting this error: undefined method `page' for #<\Array:0x007fc3ef37d308> and I can't seem to figure out what's wrong. Pagination works like a charm in other actions.

Thanks! :)


Don't use last as that will trigger the query execution. Use reverse_order and limit instead.


If you still want to paginate array:

require 'will_paginate/array'

and then use

Array#paginate (the very bottom of the page)


Need Your Help

Is there a way to create a Bigquery table with data-dependent schema in Google Dataflow?

google-bigquery google-cloud-dataflow

I am trying to create a Bigquery table as part of the dataflow. The examples show passing the schema as TableFieldSchema instance. However, the tableschema I have is data dependent, and hence can a...

Laravel : Load a view after posting

php post view laravel

In Codeigniter I used to call the view function after posting data. Like below;