有什么方法可以让我只显示当前页面链接,当我在第一页时隐藏<< Previous 链接,当我在第一页时隐藏next >> 链接我在最后一页。
应该是这样的
第一页:1 |下一步>>
在最后一页(因为有 4 页):<< previous | 4
任何中心页面的示例:<< previous | 3 |下一步 >>
目前我得到的是:<< previous | 1 ... 4 |下一步>>
我的代码
<%= will_paginate @blogs, :class=>"pagination_links",:page_links => true, :next_label => "<span>| </span>Next >>",:previous_label => "<< Previous<span> |</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>
有什么解决办法吗?
最佳答案
目前无法使用默认的 API 选项,但 will_paginate 允许您制作自定义链接渲染器。
为此,将渲染器键添加到您的 will_paginate 函数并告诉它要使用的渲染器。
<%= will_paginate @pages, renderer: PaginationLinkRenderer, previous_label:"« Previous |", next_label:"| Next »" %>
并在 helpers/或 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
关于html - rails will_paginate 仅显示当前页面链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23128447/