# Paginating\_find losing scope

**URL:** <https://www.ruby-forum.com/t/paginating-find-losing-scope/155178>\
**Category:** Rails\
**Created:** [December 9, 2008, 1:30am UTC](https://www.ruby-forum.com/t/paginating-find-losing-scope/155178 "2008-12-09T01:30:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://www.ruby-forum.com/u/scott)\
**Post date:** [December 9, 2008, 1:30am UTC](https://www.ruby-forum.com/t/paginating-find-losing-scope/155178/1 "2008-12-09T01:30:25Z")

</div>

Hello,

I’m having a problem with paginating\_find losing the context of the  
array it’s paginating.

For example,

URL: [http://localhost:3000/companies/1/users/1](http://localhost:3000/companies/1/users/1)

\<% @tickets = @user.tickets.find(:all, page =\> {:size =\>  
10, :current =\> params[:page]}) %\>  
\<% for ticket in @tickets %\>  
…  
\<% end %\>  
\<%= paginating\_links (@tickets) %\>

The problem is ‘paginating\_links’ is spitting out pagination URLs that  
look like:

[http://localhost:3000/users/1?page=2](http://localhost:3000/users/1?page=2)

instead of:

[http://localhost:3000/companies/1/users/1?page=2](http://localhost:3000/companies/1/users/1?page=2)

Any ideas why it’s losing the context of the company?

Thank you!

-scott

---

<div class="post-metadata">

**Author:** ![scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://www.ruby-forum.com/u/scott)\
**Post date:** [December 9, 2008, 4:21am UTC](https://www.ruby-forum.com/t/paginating-find-losing-scope/155178/2 "2008-12-09T04:21:11Z")

</div>

I figured out what is making this happen. I have a routes file that  
contains:

map.resources :users, :has\_many =\> [:tickets]  
map.resources :companies, :has\_many =\> [:users]

Is the paginating\_links method simply finding the first route? Any  
way to tell it the correct route/path?

Thanks,

-scott

---

<div class="post-metadata">

**Author:** ![scott](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/3e96dc/32.png) [@scott](https://www.ruby-forum.com/u/scott)\
**Post date:** [December 9, 2008, 5:50pm UTC](https://www.ruby-forum.com/t/paginating-find-losing-scope/155178/3 "2008-12-09T17:50:58Z")

</div>

Problem solved:

\<%= paginating\_links(@tickets, {:params =\>  
{:controller =\> “companies/#{@company.id}/users/#{@user.id}/”},  
:window\_size =\> 10}) %\>

Thanks for the hint Alex!
