Is it possible to combine will_paginate with find_by_sql? Is it possible to combine will_paginate with find_by_sql? ruby-on-rails ruby-on-rails

Is it possible to combine will_paginate with find_by_sql?


Use paginate_by_sql, i.e.

sql = " SELECT *         FROM   users        WHERE  created_at >= ?        ORDER  BY created_at DESC "@users = User.paginate_by_sql(  [sql, 2.weeks.ago],  page: @page,  per_page: @per_page)

As a general rule any finder can be paginated by replacing the find* with paginate*.


User.paginate_by_sql(sql, :page => params[:page], :per_page => 10)


Try this:

@users = User.find_by_sql @users = @users.paginate

What will_paginate and rails version are you using?