a link' W...">

How to configure will_paginate linkbase?

<%= will_paginate(@posts) %> # will generate the links like this '<a href="/posts?page=n">a link</a>' 

What if I want to change the href base to /contents etc. <a href="/contents?page=n">a link</a> ?

It seems that there are no options for this, help!

+4
source share
1 answer

You may have to write your own LinkRenderer. See this blog post for code for LinkRenderer.

Short:

in environment.rb you need something like this:

 WillPaginate::ViewHelpers.pagination_options[:renderer] = 'MyLinkRenderer' 

in 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 
+6
source

All Articles