# Custom find methods and pagination

**URL:** <https://www.ruby-forum.com/t/custom-find-methods-and-pagination/72390>\
**Category:** Rails\
**Created:** [December 19, 2005, 3:20pm UTC](https://www.ruby-forum.com/t/custom-find-methods-and-pagination/72390 "2005-12-19T15:20:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 19, 2005, 3:20pm UTC](https://www.ruby-forum.com/t/custom-find-methods-and-pagination/72390/1 "2005-12-19T15:20:33Z")

</div>

i’ve got several methods in my models i use to find based on certain  
criteria…i’ve done this so the controller code is less cluttered, plus  
the  
DRY factor.

example:

class Foo \< ActiveRecord::Base

def find\_by\_something(something)  
find :all, :joins =\> …, :conditions =\> …  
end

def find\_by\_something\_else(something\_else)  
find :all, :joins =\> …, :conditions =\> …  
end

def find\_by\_something\_and\_bar(something, bar)  
find :all, :joins =\> …, :conditions =\> …  
end

now my question:

is there a way to do Foo.find\_by\_something(something) in a paginator?  
would  
I have to modify all my methods to accept a limit and offset parameter?

thanks

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 19, 2005, 10:14pm UTC](https://www.ruby-forum.com/t/custom-find-methods-and-pagination/72390/2 "2005-12-19T22:14:10Z")

</div>

I’ve been trying to do the same thing. Is this possible or is the only  
way to do this is putting your queries in the controller?

> now my question:
> 
> is there a way to do Foo.find\_by\_something(something) in a paginator?  
> would  
> I have to modify all my methods to accept a limit and offset parameter?
> 
> thanks

---

<div class="post-metadata">

**Author:** ![bigdaddy71](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/bbe5ce/32.png) [@bigdaddy71](https://www.ruby-forum.com/u/bigdaddy71)\
**Post date:** [December 19, 2005, 11:15pm UTC](https://www.ruby-forum.com/t/custom-find-methods-and-pagination/72390/3 "2005-12-19T23:15:58Z")

</div>

Chris H. wrote:

> end
> 
> is there a way to do Foo.find\_by\_something(something) in a paginator?  
> would I have to modify all my methods to accept a limit and offset  
> parameter?

This question seems to be asked a couple times a week on this list but  
never resolved. I also banged my head against this and ultimately gave  
up and put my conditions in the controller/pagination rather than in the  
model where I’d like it to be.

I believe it can’t be done with the current paginator. Hopefully,  
someone more knowledgeable can prove me wrong 🙂

John
