How to Implement ajax pagination with will_paginate gem

Create a new helper (ex. app/helpers/will_paginate_helper.rb) with the following content: module WillPaginateHelper class WillPaginateJSLinkRenderer < WillPaginate::ActionView::LinkRenderer def prepare(collection, options, template) options[:params] ||= {} options[:params][‘_’] = nil super(collection, options, template) end protected def link(text, target, attributes = {}) if target.is_a? Fixnum attributes[:rel] = rel_value(target) target = url(target) end @template.link_to(target, attributes.merge(remote: true)) do text.to_s.html_safe end end end … Read more

Overriding a module method from a gem in Rails

A more concise solution: WillPaginate::Finder::ClassMethods.module_eval do def paginate_by_sql sql, options # Your code here end end Put the the code into an initializer file in config/initializers. This is the correct place to put code that needs to be run when the environment is loaded. It also better organises your code, making each file’s intent clearer, … Read more