2014-01-14 31 views
1

在一個簡單的CRUD rails應用程序中,我使用的是will_paginate gem。我決定刪除頁碼以及previous_link按鈕。我只渲染next_link。用will_paginate gem在最後一頁顯示消息

<%= will_paginate @posts, :page_links => false, :next_label => 'more', :previous_label => '' %> 

我該如何去在最後一頁上顯示自定義消息。如「這是結束。」

我想我可能必須重寫will_paginate的一些方法,並在視圖中放置某種布爾值?

回答

2

一個來實現,這是增加了一些條件對視圖方式:

<% prev = (@posts.total_pages == @posts.current_page) ? '' : 'prev' %> 
<%= will_paginate @posts, :page_links => false, :next_label => 'more', :previous_label => prev %> 
3

移動到應用程序/資產/樣式表/ application.css有以下CSS在文件

.apple_pagination { 
    background: #f1f1f1; 
    border: 1px solid #e5e5e5; 
    text-align: center; 
    padding: 1em; 
    cursor: default; } 
    .apple_pagination a, .apple_pagination span { 
    padding: 0.2em 0.3em; } 
    .apple_pagination .disabled { 
    color: #aaaaaa; } 
    .apple_pagination .current { 
    font-style: normal; 
    font-weight: bold; 
    background-color: #bebebe; 
    display: inline-block; 
    width: 1.4em; 
    height: 1.4em; 
    line-height: 1.5; 
    -moz-border-radius: 1em; 
    -webkit-border-radius: 1em; 
    border-radius: 1em; 
    text-shadow: rgba(255, 255, 255, 0.8) 1px 1px 1px; } 
    .apple_pagination a { 
    text-decoration: none; 
    color: black; } 
    .apple_pagination a:hover, .apple_pagination a:focus { 
     text-decoration: underline; } 

移動到應用程序/視圖/ index.html.erb

<%= will_paginate @posts ,:class => "apple_pagination"%> 

你會發現最後頁碼是結束的。

在posts_controller.rb

另外

@posts = Post.order( 「published_at DESC」)頁(PARAMS [:頁])。per_page(20)

相關問題