Forum: Ruby on Rails custom find methods and pagination

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Chris H. (Guest)
on 2005-12-19 16:20
(Received via mailing list)
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
charlie bowman (Guest)
on 2005-12-19 23:14
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
John D. (Guest)
on 2005-12-20 00:15
(Received via mailing list)
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
This topic is locked and can not be replied to.