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