简体   繁体   English

Rails-使用Kaminari进行分页吗?

[英]Rails - Using Kaminari for pagination?

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 调用link_to_next_page时出现以下错误

undefined method `link_to_next_page' 未定义的方法“ 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: 您可以将整个帮助程序模块包含在控制器中,但最好使用view_context访问特定的帮助程序方法:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM