Forum: Ruby on Rails How can I use Pagination on Model associations?

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.
leonleslie (Guest)
on 2005-11-17 19:30
(Received via mailing list)
I have the following code

@components_pages = Paginator.new self,
Computer.find(params[:id]).components.count,
2, @params['page']

How can I restrict find to only return associations(components) for the
current page?
@computer = Computer.find(params[:id] .....................

I spent a few hours thinking about this one but to no avail

regards,
Leon.
Roberto S. (Guest)
on 2005-11-17 21:25
(Received via mailing list)
I also has this problem and solved it by using conditions (accroding to
the
associaltions) in the paginate definition. But I i don't think this is a
nice solution. Are there better ways of doing that ?

regards

On 11/17/05, Leon L. <removed_email_address@domain.invalid> wrote:
> I spent a few hours thinking about this one but to no avail
>
> --
Roberto S. - http://rsaccon.com
leonleslie (Guest)
on 2005-11-17 23:17
(Received via mailing list)
Hi Saccon,

Thanks for your quick reply to the post.

Do you have an example?

It would be cool if one could limit includes in associations, but this
is
just my mad method of thinking. Can i have a view of your conditions and
how
you did it?

regards,
Leon.
Joe B. (Guest)
on 2005-11-18 10:37
Computer.find(:first,
              :conditions => ["id=?", params[:id]]).components.count

__________________________________________________________
or
Computer.find(:first,
              :conditions => ["id=? and price>?", params[:id],
3000]).components.count


i hope that's make sense.
This topic is locked and can not be replied to.