Link renderer

Mislav Marohnić edited this page May 22, 2014 · 3 revisions

If you need to customize HTML output of will_paginate, you'll need to subclass WillPaginate::ActionView::LinkRenderer, and pass that object with the :renderer option.

There is no documentation how to write your own link renderer, but the source code is pretty self-explanatory. Dive into it, and selectively override methods of the LinkRenderer to adjust them to your needs.

Happy hacking!

Change the default link renderer for your application

module ApplicationHelper
  # change the default link renderer for will_paginate
  def will_paginate(collection_or_options = nil, options = {})
    if collection_or_options.is_a? Hash
      options, collection_or_options = collection_or_options, nil
    end
    unless options[:renderer]
      options = options.merge :renderer => MyCustomLinkRenderer
    end
    super *[collection_or_options, options].compact
  end
end