I have run into some problems with the Rails paginate helper. Given a
relatively complex pagination search including joins etc, the
@item_count is set incorrectly. This is because the
paginator_and_collection_for uses model.count with does not accept a
SELECT DISTINCT query.
I have made a small change to paginator_and_collection_for to allow a
custom query for counting. The new version is:
def paginator_and_collection_for(collection_id, options) #:nodoc:
klass = options[:class_name].constantize
page = params[options[:parameter]]
unless options[:custom_search].nil?
count = eval(options[:custom_search])
else
count = count_collection_for_pagination(klass, options)
end
paginator = Paginator.new(self, count, options[:per_page], page)
collection = find_collection_for_pagination(klass, options,
paginator)
return paginator, collection
end
I have also changed the DEFAULT_OPTIONS to support the :custom_search
option.
My question is, how to make this change within my app, to overload the
existing rails implementation. I understand that it is very bad form to
modify the rails source on my machine, so am looking for a tidy
alternative.
Does anyone have examples of overloading methods of modules such as
Pagination?
Kim