[英]Displaying message on last page with will_paginate gem
Within a simple CRUD rails app, I am using the will_paginate gem . 在一个简单的CRUD rails应用程序中,我正在使用will_paginate gem 。 I've decided to remove the page numbers as well as the previous_link button.
我已经决定删除页码以及previous_link按钮。 I am only rendering the next_link.
我只渲染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? 我在想我可能必须重写will_paginate的某些方法,并在视图中放入某种布尔值?
Move to app/assets/Stylesheets/application.css have the following css in your file 移至app / assets / Stylesheets / 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; }
Move to app/views/index.html.erb 移至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_controller.rb中
@posts = Post.order("published_at desc").page(params[:page]).per_page(20) @posts = Post.order(“ published_at desc”)。page(params [:page])。per_page(20)
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 %>
That is a good way @Talgat suggested: check out these answers on here as well: 这是@Talgat建议的一种好方法:也在此处查看以下答案:
will_paginate show the last page by default (keeping chronological order) will_paginate默认显示最后一页(按时间顺序)
will_paginate find out if I'm on the last page will_paginate找出我是否在最后一页
Rails 3 and will_paginate - elegant way, how to get total_pages Rails 3和will_paginate-优雅的方式,如何获取total_pages
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.