简体   繁体   English

在 Rails 中的分页 gem 中,您如何在不需要时隐藏分页?

[英]In pagy gem in rails, how do you hide pagination when unneeded?

The pagination works well when it's needed.需要时分页效果很好。 But even when it's not needed -- for example, when # set for pagination is 100 and the list is less than 100 --, the pagination shows like this:但即使不需要它——例如,当#set for pagination 是 100 并且列表小于 100——时,分页显示如下:

‹ Prev 1 Next › ‹ 上一页 1 下一页 ›

How can I eliminate this?我怎样才能消除这种情况?

My controller:我的控制器:

    @pagy, @users = pagy(User.all, items:100, link_extra: 'class="" style="color:#222222; margin-left:3px;"')

My view:我的看法:

    <%== pagy_nav(@pagy) %>

Otherwise followed the documentation否则遵循文档

The solution was to add this line:解决方案是添加这一行:

<%== pagy_nav(@pagy) if @pagy.pages > 1 %>

Because unlike will_paginate or other pagination gems, pagy does not hide the link automatically.因为与 will_paginate 或其他分页宝石不同,pagy 不会自动隐藏链接。

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

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