Custom find methods and pagination


#1

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


#2

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


#3

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 :slight_smile:

John