will_paginate - 如果集合为空或小于每页参数,则不显示页面条目信息
假设我有一个创建 WillPaginate 集合的控制器操作:
@comments = WillPaginate::Collection.new(@page_num, 15, @comments.length).concat(comments_to_paginate)
那么在我看来:
<div class="pag">
<div clas="page_info">
<%= page_entries_info @comments %>
</div>
<%= will_paginate @comments, :container => false %>
</div>
现在我想做的是不显示 page_entries_info 输出,如果 (1) 没有注释,并且 (2) 如果条目数(例如, 7) 小于每页限制 (15)。
你会如何处理这个问题?
Let's say I have a controller action that creates the WillPaginate collection:
@comments = WillPaginate::Collection.new(@page_num, 15, @comments.length).concat(comments_to_paginate)
Then in my view:
<div class="pag">
<div clas="page_info">
<%= page_entries_info @comments %>
</div>
<%= will_paginate @comments, :container => false %>
</div>
Now what I want to do is to NOT show the page_entries_info output if (1) there are no comments and (2) if the number of entries (eg, 7) is less than the per page limit (15).
How would you go about handling this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您只需要使用您希望的条件来保护您的
page_entries_info
例如
,或者您可以将其放入您的控制器中并保持您的视图更清晰,如果您需要相同的变量,也可以让您有一个可以重用的变量保护视图代码的其他部分。
然后在视图中:
如果你可以处理额外的div,那么这也应该有效
You just need to guard your
page_entries_info
with the conditions you wishFor example
Or you can put this in your controller and keep your view a little cleaner, also letting you have one variable to reuse if you need the same guard around other parts of view code.
Then in the view:
If you can deal with the extra div, then this should also work