Reputation: 77646
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')
Upvotes: 0
Views: 988
Reputation: 77646
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
Upvotes: 0
Reputation: 3342
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!
Upvotes: 1