One of the way to implement this is adding some conditions on view:
<% prev = (@posts.total_pages == @posts.current_page) ? '' : 'prev' %>
<%= will_paginate @posts, :page_links => false, :next_label => 'more', :previous_label => prev %>
题
Within a simple CRUD rails app, I am using the will_paginate gem. I've decided to remove the page numbers as well as the previous_link button. I am only rendering the next_link.
<%= will_paginate @posts, :page_links => false, :next_label => 'more', :previous_label => '' %>
How would I go about displaying a custom message on the last page. Such as "this is the end."
I'm thinking I might have to override some of the methods for will_paginate and put some sort of boolean in the view?
解决方案 2
One of the way to implement this is adding some conditions on view:
<% prev = (@posts.total_pages == @posts.current_page) ? '' : 'prev' %>
<%= will_paginate @posts, :page_links => false, :next_label => 'more', :previous_label => prev %>
其他提示
Move to app/assets/Stylesheets/application.css have the following css in your file
.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; }
Move to app/views/index.html.erb
<%= will_paginate @posts ,:class => "apple_pagination"%>
You will find the last page number which is an end.
Also in posts_controller.rb
@posts = Post.order("published_at desc").page(params[:page]).per_page(20)
That is a good way @Talgat suggested: check out these answers on here as well:
will_paginate show the last page by default (keeping chronological order)
will_paginate find out if I'm on the last page
Rails 3 and will_paginate - elegant way, how to get total_pages