# Overloading paginate method

**URL:** <https://www.ruby-forum.com/t/overloading-paginate-method/117566>\
**Category:** Rails\
**Created:** [October 18, 2007, 4:22am UTC](https://www.ruby-forum.com/t/overloading-paginate-method/117566 "2007-10-18T04:22:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![kimchirnside](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/48db29/32.png) [@kimchirnside](https://www.ruby-forum.com/u/kimchirnside)\
**Post date:** [October 18, 2007, 4:22am UTC](https://www.ruby-forum.com/t/overloading-paginate-method/117566/1 "2007-10-18T04:22:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kimchirnside](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/48db29/32.png) [@kimchirnside](https://www.ruby-forum.com/u/kimchirnside)\
**Post date:** [October 18, 2007, 4:49am UTC](https://www.ruby-forum.com/t/overloading-paginate-method/117566/2 "2007-10-18T04:49:20Z")

</div>

Hi Kim

Take a lot at activescaffold where pagination is taken of pretty  
nicely.

On Oct 18, 10:22 am, Kim C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
