【问题标题】:rails will_paginate display current page link onlyrails will_paginate 仅显示当前页面链接
【发布时间】:2014-04-17 08:41:58
【问题描述】:

有什么办法可以让我只显示当前页面链接,当我在第一页时隐藏链接,而当我在第一页时隐藏下一个>>链接我在最后一页。
应该是这样的

在第一页:1 |下一页>>

在最后一页(因为有 4 页):

任何中心页面的示例:>

目前我得到的是:>

我的代码

<%= will_paginate @blogs, :class=>"pagination_links",:page_links => true, :next_label => "<span>|&nbsp</span>Next >>",:previous_label => "<< Previous<span>&nbsp|</span>",:inner_window   => 0, :outer_window => 0 %> 

生成的html是

<div class="pagination_links">
<span class="previous_page disabled">
<< Previous
<span> |</span>
</span>
<em class="current">1</em>
<span class="gap">…</span>
<a href="/blog?page=4">4</a>
<a class="next_page" href="/blog?page=2" rel="next">
<span>| </span>
Next >>
</a>
</div>

有什么解决办法吗?

【问题讨论】:

    标签: html css ruby-on-rails will-paginate


    【解决方案1】:

    目前无法使用默认 API 选项,但 will_paginate 允许您制作自定义链接渲染器。

    为此,将渲染器键添加到 will_paginate 函数并告诉它使用什么渲染器。

     <%= will_paginate @pages, renderer: PaginationLinkRenderer, previous_label:"« Previous |", next_label:"| Next »" %>
    

    并在 helpers/ 或 lib/ 中创建一个名为 pagination_link_renderer.rb 的文件并添加以下内容:

    class PaginationLinkRenderer < WillPaginate::ActionView::LinkRenderer
    
      protected
    
      def page_number(page)
       if page == current_page
         page
       end
      end
    
      def previous_or_next_page(page, text, classname)
        if page
          link(text, page, class: classname)
        end
      end
    
    end
    

    【讨论】:

      【解决方案2】:

      我使用 css 实现了这一点

         .current {
              display: inline-block;
              font-size: 12px;
              text-decoration: none;
              color: #000000;
          }
          .gap{
              display : none !important;
          }
          .pagination_links a{
              display:none;
          }
          .next_page,.previous_page{
              display:inline-block !important;
              color: #3343A0;
          }
          .pagination_links{
              text-align: center;
          }
          .previous_page.disabled, .next_page.disabled{
              display: none !important;
          }        
          .pagination_links a{
              text-decoration: none;
          }
          .pagination_links a:hover{
              text-decoration: underline;
          }
          .pagination_links span{
              text-decoration: none;
              display: inline-block;
              color: #000000;
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-01
        • 2012-03-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-15
        相关资源
        最近更新 更多