A more concise solution:
def paginate_by_sql sql, options
# Your code here
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, thus bugs will be easier to track down. Do not clutter up environment.rb!