Pagination

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

but unable to fix this issue.

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


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

-----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. :wink:

http://www.rubyonrails.com/community


Phillip G.
Twitter: twitter.com/cynicalryan
Blog: 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

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


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

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
Sent from the JRuby - User mailing list archive at Nabble.com.


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

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.

http://errtheblog.com/posts/56-im-paginating-again

-Tyler

On 5/21/08, aratnam [email protected] 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs