2014-04-17 51 views
0

有没有什么办法,使我可以只显示当前页面链接< <上一页链接隐藏当我第一页和下一页>>上链接隐藏当我在最后一页。
它应该如下轨will_paginate显示当前页面的链接只有

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

最后一页(因为有4页):< <前一页| 4

任何中心页面的示例:< <上一页| 3 |下一页>>

目前我所得到的是:< <前一页| 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> 

这方面的任何解决方案?

回答

0

我实现了这个使用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; 
    } 
0

使用默认的API选项这目前不可能,但will_paginate允许您自定义链接渲染器。

为此,请将渲染器键添加到will_paginate函数中,并告诉它要使用的渲染器。

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

,并创建无论是在助手/或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 
相关问题