# Problem with pagination, rails

**URL:** <https://www.ruby-forum.com/t/problem-with-pagination-rails/80202>\
**Category:** Ruby\
**Created:** [December 22, 2006, 3:06am UTC](https://www.ruby-forum.com/t/problem-with-pagination-rails/80202 "2006-12-22T03:06:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![shawn\_bright](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@shawn\_bright](https://www.ruby-forum.com/u/shawn_bright)\
**Post date:** [December 22, 2006, 3:06am UTC](https://www.ruby-forum.com/t/problem-with-pagination-rails/80202/1 "2006-12-22T03:06:23Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![shawn\_bright](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@shawn\_bright](https://www.ruby-forum.com/u/shawn_bright)\
**Post date:** [December 22, 2006, 3:56am UTC](https://www.ruby-forum.com/t/problem-with-pagination-rails/80202/2 "2006-12-22T03:56:28Z")

</div>

> ```
> 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.

---

<div class="post-metadata">

**Author:** ![shawn\_bright](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/838e76/32.png) [@shawn\_bright](https://www.ruby-forum.com/u/shawn_bright)\
**Post date:** [December 22, 2006, 4:18am UTC](https://www.ruby-forum.com/t/problem-with-pagination-rails/80202/3 "2006-12-22T04:18:29Z")

</div>

right, sorry, i will use the rails list for this kinda thing.

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

sk
