I'm trying to get the next page link. How would I do this? I get the following error when calling link_to_next_page
undefined method `link_to_next_page'
query = Posts.page(1).per(5).includes(author: :profile)
link = link_to_next_page(query, 'Next-Page')
Link helpers are not accessible into controllers. You can include entire helper module into your controller, but better use view_context
to access particular helper method:
query = Posts.page(1).per(5).includes(author: :profile)
link = view_context.link_to_next_page(query, 'Next-Page')
Good luck!
def paginate(query)
query.offset!((@page-1) * @per_page)
query.limit!(@per_page+1)
result = query.to_a
if (result.size > @per_page)
result.pop
response.headers['Link'] = CREATE_NEXT_AGE_LINK_HERE
end
result
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.