Kaminari分页,如何获取当前页码?
我正在使用 Kaminari 对数据库查询的一些结果进行分页。
我想对结果的第一页应用特定的样式。 一旦我知道用户在哪个页面,操作就很容易,但我找不到检测当前页面的方法。
I am using Kaminari to paginate some results from a db query.
I would like to apply specific styling to the first page of the results.
The operation is very easy once I know on what page the user is, but I can't find a way to detect the current page.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你想检查第一页,你可以这样做:
如果你找到特定页面,你可以这样做:
current_page_no = object.current_page
有关更多信息,请参阅: http://www.rubydoc.info/github/amatsuda/kaminari/master/Kaminari/PageScopeMethods
If you want to check for first page you can do it like this:
If you find the specific page you can do something like this:
current_page_no = object.current_page
For more info refer: http://www.rubydoc.info/github/amatsuda/kaminari/master/Kaminari/PageScopeMethods
2020 更新。截至目前,我可以执行
@users.current_page
。2020 Update. As of now I am able to do
@users.current_page
.您生成了 kaminari 使用的部分吗?
请参阅此处标题为“自定义分页助手”的部分:
https://github.com/ amatsuda/kaminari
完成此操作后,您可以编辑 _paginator.html.erb 文件(或其他 kaminari 部分文件,如果需要)以获得您想要的分页功能 寻找。这些部分允许您使用局部变量,例如“current_page”、“num_pages”等等。听起来这就是您要找的。
如果您想在运行生成器之前查看它们,这些部分的外观如下:
https://github.com/amatsuda/kaminari/tree/master/app/views/kaminari
希望能为您指明正确的方向。
Have you generated the partials that kaminari uses?
See the section titled "Customizing the pagination helper" here:
https://github.com/amatsuda/kaminari
Oncey ou do that, you can edit the _paginator.html.erb file (or other kaminari partials if you need to) in order to get the pagination functionality you're looking for. These partials allow you to use local variables, like "current_page", "num_pages" and a few more. Sounds like that's what you're looking for.
Here's what those partials look like, if you want to see them before running the generator:
https://github.com/amatsuda/kaminari/tree/master/app/views/kaminari
Hope that points you in the right direction.