will_paginate:如何构建“下一页”链接?
我知道这一定非常简单,但环顾四周后我找不到答案。
我正在使用will_paginate插件,我喜欢有一个简单的“下一页”链接,而不是整个will_paginate链接集合。
我怎样才能做到这一点?
谢谢!
这将为您提供一个简单的下一个按钮。
protected # Tells WP how to render the "Next Page" link def next_page # The only difference from the default here is we renamed the link to "More" # and added a custom class, twitter_pagination previous_or_next_page(@collection.next_page, "Next", 'twitter_pagination') if @collection.next_page end # Remove all links except our :next_page def pagination [ :next_page ] end
让我们知道您的身体情况如何。 这是一篇很棒的博客文章,你也应该阅读。 让我们知道您的身体情况如何。 祝一切顺利。
它实际上比你想象的要多得多,有些人可能称之为“Rails Way”。 http://thewebfellas.com/blog/2008/8/3/roll-your-own-pagination-links-with-will_paginate
但是你也可以做一个帮手,并使用方法current_page
和total_pages
。 所以类似于:
<% if @post.current_page < @post.total_pages %> <%= link_to "Next", "#{posts_path(@post)}?page=#{@post.current_page+1}" %> <% end %>
在Rails v4上使用will_paginate v3:
<%= will_paginate @posts, :page_links=>false %>
- 在tags / show.html.erb中显示post_tag_links
- 使用activerecord发出请求,仅从组中获取用户,而不从其他用户获取
- 从RubyMine迁移到Vim – 解释自动完成
- Rails使用什么Ruby技术来使我的控制器方法呈现视图?
- 你如何处理开发中的SSL?
- Rails:如何使用params范围和使用params默认值的路由
- Rails在分组后显示最新值
- ActiveRecord :: Base的未定义方法`mysql_connection’:Class
- Schema.rb显示由于以下NoMethodError#undefined方法`’为nil:NilClass,因此无法转储表“progress”