Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails will_paginate-don';如果集合为空或小于每页参数,则不显示页面条目信息_Ruby On Rails_Will Paginate - Fatal编程技术网

Ruby on rails will_paginate-don';如果集合为空或小于每页参数,则不显示页面条目信息

Ruby on rails will_paginate-don';如果集合为空或小于每页参数,则不显示页面条目信息,ruby-on-rails,will-paginate,Ruby On Rails,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 %>

假设我有一个创建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>

假%>
现在我想做的是,如果(1)没有评论,(2)如果条目数(如7)小于每页限制(15),则不显示页面条目信息输出


您将如何处理此问题?

您只需按照您希望的条件保护您的
页面\u条目\u信息

比如说

<div class="pag">
  <% if @comments.length > 0 && @comments.total_pages > 1 %>
    <div class="page_info">
      <%= page_entries_info @comments %>
    </div>
  <% end %>
  <%= will_paginate @comments, :container => false %>
</div>
然后在视图中:

<div class="pag">
  <% if @show_pagination %>
    <div class="page_info">
      <%= page_entries_info @comments %>
    </div>
  <% end %>
  <%= will_paginate @comments, :container => false %>
</div>

假%>
如果您可以处理额外的div,那么这也应该有效

<div class="pag">
  <div class="page_info">
    <%= page_entries_info(@comments) if @show_pagination %>
  </div>
  <%= will_paginate @comments, :container => false %>
</div>

假%>

很好的示例选项。非常感谢。
<div class="pag">
  <div class="page_info">
    <%= page_entries_info(@comments) if @show_pagination %>
  </div>
  <%= will_paginate @comments, :container => false %>
</div>