Forum: Ruby problem with pagination, rails

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.
shawn bright (Guest)
on 2006-12-22 04:06
(Received via mailing list)
lo there all,
i am having some trouble getting pagination going the way i need for a
rails
app.

the controller looks like this

def summary
        @site_pages, @sites = paginate(:sites,
                            :conditions => ['group_id = ?', @group.id],
                            :order         => 'site_name'   )
    end


the problem is that it is listing every site, not just those belonging
to group

anyone know what i can do about this ?

thanks,

sk
Giles B. (Guest)
on 2006-12-22 04:56
(Received via mailing list)
>     end
>
>
> the problem is that it is listing every site, not just those belonging to group
>
> anyone know what i can do about this ?

I hate to say this but the best thing is to take this question to the
Rails list; the Ruby list is more about Ruby in general than Rails
specifically. What you're dealing with there is definitely a Rails
question.

That being said, my guess is that you can probably solve it by doing

paginate(@group.sites, :order => "site_name")

Since you've already got the group, and the sites appear to belong to
it. **If** I'm right then you'll also make your app more efficient by
doing this, since the way you have it now looks as if it involves an
additional SQL call.

Alternatively, if the @group.sites thing doesn't work and it looks as
if you need to do a SQL call to do any pagination, don't, just search
for "paginate_collection" and "canadaduane" on Google. Add the
paginate_collection code to your application controller and you'll be
a happy camper.
shawn bright (Guest)
on 2006-12-22 05:18
(Received via mailing list)
right, sorry, i will use the rails list for this kinda thing.

btw, the @group.sites thing did work. Thanks.

sk
This topic is locked and can not be replied to.