<%= will_paginate(@posts) %>
# will generate the links like this '<a href="/posts?page=n">a link</a>'
如果我想改变/contents
的href怎么办?等<a href="/contents?page=n">a link</a>
?
好像没有这个选项,求助!
最佳答案
您可能必须编写自己的 LinkRenderer。参见 this博客文章和 code对于 LinkRenderer。
简要说明:
在 environment.rb
中你需要这样的东西:
WillPaginate::ViewHelpers.pagination_options[:renderer] = 'MyLinkRenderer'
在 application_helper.rb
class MyLinkRenderer < WillPaginate::LinkRenderer
def page_link(page, text, attributes = {})
url = url_for(page) # you should find a better way to do this...
url.sub!('posts','contents')
@template.link_to text, url, attributes
end
end
关于ruby - 如何自定义 will_paginate 链接库?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3430975/