2014-04-17 52 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 
相關問題