# Where to put pagination\_by\_sql code?

**URL:** <https://www.ruby-forum.com/t/where-to-put-pagination-by-sql-code/105658>\
**Category:** Rails\
**Created:** [June 1, 2007, 3:50am UTC](https://www.ruby-forum.com/t/where-to-put-pagination-by-sql-code/105658 "2007-06-01T03:50:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmehta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ea666f/32.png) [@rmehta](https://www.ruby-forum.com/u/rmehta)\
**Post date:** [June 1, 2007, 3:50am UTC](https://www.ruby-forum.com/t/where-to-put-pagination-by-sql-code/105658/1 "2007-06-01T03:50:38Z")

</div>

I am trying to use the pagination\_by\_sql explained here :

[http://thebogles.com/blog/2006/06/paginate\_by\_sql-for-rails-a-more-general-approach/](http://thebogles.com/blog/2006/06/paginate_by_sql-for-rails-a-more-general-approach/)

Now I don’t know where to put the following code sso that all the models  
could use it.

module ActiveRecord  
class Base  
def self.find\_by\_sql\_with\_limit(sql, offset, limit)  
sql = sanitize\_sql(sql)  
add\_limit!(sql, {:limit =\> limit, :offset =\> offset})  
find\_by\_sql(sql)  
end

```
    def self.count_by_sql_wrapping_select_query(sql)
        sql = sanitize_sql(sql)
        count_by_sql("select count(*) from (#{sql}) as my_table")
    end

```

end  
end

But I can’t figure out where the code for ActiveRecord would go? Where  
is the activerrecord base class in the directory structure to modify?

Thanks.
