# Pagination

**URL:** <https://www.ruby-forum.com/t/pagination/138308>\
**Category:** JRuby\
**Created:** [May 21, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/pagination/138308 "2008-05-21T22:37:38Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aratnam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@aratnam](https://www.ruby-forum.com/u/aratnam)\
**Post date:** [May 21, 2008, 10:37pm UTC](https://www.ruby-forum.com/t/pagination/138308/1 "2008-05-21T22:37:38Z")

</div>

I am trying to paginate a collection on the controller and when I try to  
access the Paginator from view using

\<%= link\_to “Previous page”, {:page =\> @list\_pages.current.previous } if  
@list\_pages.current.previous %\>  
\<%= link\_to “Next page”, {:page =\> @list\_pages.current.next } if  
@list\_pages.current.next %\>

I get the following error

You have a nil object when you didn’t expect it!  
The error occurred while evaluating nil.current

Extracted source (around line #155):

152: \<%end%\>  
153:  
154: \<%= link\_to “Previous page”, {:page =\>  
@list\_pages.current.previous  
} if @list\_pages.current.previous %\>  
155: \<%= link\_to “Next page”, {:page =\> @list\_pages.current.next }  
if  
@list\_pages.current.next %\>  
156:   
157:

In the controller am using

def paginate\_collection(coll, options = {})  
require ‘java’  
include\_class “java.util.ArrayList”  
paged = ArrayList.new  
default\_options = {:per\_page =\> 5, :page =\> 1}  
options = default\_options.merge options

```
pages = Paginator.new self, coll.size, options[:per_page],

```

options[:page]  
first = pages.current.offset  
last = [first + options[:per\_page], coll.size].min  
for i in first…last  
paged.add(coll.get(i));  
end  
return [pages, paged]  
end

and I call this in the controller from  
def list  
#list\_col is a collection  
@list\_pages, @list = paginate\_collection(@list\_col, :page =\>  
params[:page])  
end

How should I access the Paginator from view, I read through this post

> **[O'Reilly Media - Technology and Business Training](https://www.oreilly.com)**
>
> Gain technology and business knowledge and hone your skills with learning resources created and curated by O'Reilly's experts: live online training, video, books, our platform has content from 200+ of the world's best publishers.

## but unable to fix this issue.

View this message in context:  
[http://www.nabble.com/Pagination-tp17373355p17373355.html](http://www.nabble.com/Pagination-tp17373355p17373355.html)  
Sent from the JRuby - User mailing list archive at [Nabble.com](http://Nabble.com).

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```

---

<div class="post-metadata">

**Author:** ![aratnam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@aratnam](https://www.ruby-forum.com/u/aratnam)\
**Post date:** [May 21, 2008, 11:01pm UTC](https://www.ruby-forum.com/t/pagination/138308/2 "2008-05-21T23:01:44Z")

</div>

-----BEGIN PGP SIGNED MESSAGE-----  
Hash: SHA1

aratnam wrote:  
| I am trying to paginate a collection on the controller and when I try to  
| access the Paginator from view using

Asking this question at the Rails community might be better, as this is  
neither a Ruby nor JRuby question. 😉

> **[Community](https://rubyonrails.org/community)**
>
> A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.

* * *

Phillip G.  
Twitter: [twitter.com/cynicalryan](http://twitter.com/cynicalryan)  
Blog: [http://justarubyist.blogspot.com](http://justarubyist.blogspot.com)

10 years ago I was so ignorant, I didn’t even know who the  
Prime Minister of America was.  
-----BEGIN PGP SIGNATURE-----  
Version: GnuPG v1.4.8 (MingW32)  
Comment: Using GnuPG with Mozilla - [http://enigmail.mozdev.org](http://enigmail.mozdev.org)

iEYEARECAAYFAkg0iwwACgkQbtAgaoJTgL/TWQCeKWjsQ9376KqoW85SDrhdqCvh  
01QAnAwqCPobE+RU/TbiL9Fdrsh5QoOZ  
=8Vf0  
-----END PGP SIGNATURE-----

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```

---

<div class="post-metadata">

**Author:** ![aratnam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@aratnam](https://www.ruby-forum.com/u/aratnam)\
**Post date:** [May 22, 2008, 3:52pm UTC](https://www.ruby-forum.com/t/pagination/138308/3 "2008-05-22T15:52:56Z")

</div>

Thanks I will try your suggestion and also post my question in the rails  
community.

Tyler J. wrote:

> -Tyler
> 
> > @list\_pages.current.previous  
> > require ‘java’  
> > paged.add(coll.get(i));
> 
> ```
> http://xircles.codehaus.org/manage_email
> 
> ```

–  
View this message in context:  
[http://www.nabble.com/Pagination-tp17373355p17404694.html](http://www.nabble.com/Pagination-tp17373355p17404694.html)  
Sent from the JRuby - User mailing list archive at [Nabble.com](http://Nabble.com).

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```

---

<div class="post-metadata">

**Author:** ![aratnam](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@aratnam](https://www.ruby-forum.com/u/aratnam)\
**Post date:** [May 21, 2008, 11:01pm UTC](https://www.ruby-forum.com/t/pagination/138308/4 "2008-05-21T23:01:44Z")

</div>

Not to derail your question, but I would suggest using the  
will\_paginate plugin. It does the kind of collection pagination you  
want and it is much simpler to use.

I’d also suggest directing Rails specific questions to the RoR user’s  
list, they might be in a better position to help you out.

> **[I'm Paginating Again — err.the\_blog](https://errtheblog.com/posts/56-im-paginating-again)**
>
> Err the Blog: Ruby and Rails from the front.

-Tyler

On 5/21/08, aratnam [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> @list\_pages.current.next %\>  
> options = default\_options.merge options
> 
> but unable to fix this issue.

* * *

To unsubscribe from this list, please visit:

```
http://xircles.codehaus.org/manage_email

```
