Forum: Ruby on Rails Pagination problem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
C45e8b0eac09ee52dd88142e99b1094b?d=identicon&s=25 Arunkumar Balu (arun)
on 2006-05-23 15:20
hi everybody,

i am new to rails..
plz clear my doubt...

this is my question

In my table(public_topics), i have 11 rows of data..
whenever i run the following view, it shows the entire rows in the
current page..
and i have set the ':per_page' option to '2'.so it must show two data
per page..but it shows all the rows in a single page..and this case
continue in all the pagination links..

It seems that pagination is not working..
whenever i click the pagination links,nothing change and the same page
reload again with the same data...

i hope this group will definetely help me to get rid of this simple
problem..

my view and the listing method is given below...

---------------------------------------
This is my controller/method
---------------------------------------
def listtopics

 @public_topic_pages, @public_topics = paginate(:public_topics,
:per_page=>2)
 @public_topics=PublicTopic.find_by_sql("select * from public_topics
where category='" + params[:id] + "'" )

  end
-----------------------------------------------

This is my view
---------------
<%= error_messages_for 'public_topic' %>
<label for="public_topic"><h1 class="style1"><u>Questions</u></h1>
</label>
<% for public_topic in @public_topics %>
<div class="entry">
<p>
<h4><%=link_to "#{public_topic.topic}",:action=>"part" %></h4>
</p>
</div>
<% end -%>
<hr>
<%= if @public_topic_pages.current.previous
link_to "<< Prev ", { :page => @public_topic_pages.current.previous }
end %>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<%= if @public_topic_pages.current.next
link_to "Next >>", { :page => @public_topic_pages.current.next }
end %>
<hr>

-------------------------------------------------------------

plz help me....


with regards,
Arun.
5d15c6821f3c3054c04b85471824ba7c?d=identicon&s=25 Kevin Olbrich (Guest)
on 2006-05-23 15:53
(Received via mailing list)
On Tuesday, May 23, 2006, at 3:20 PM, Arunkumar Balu wrote:
>and i have set the ':per_page' option to '2'.so it must show two data
>my view and the listing method is given below...
>
><p>
>end %>
>--
>Posted via http://www.ruby-forum.com/.
>_______________________________________________
>Rails mailing list
>Rails@lists.rubyonrails.org
>http://lists.rubyonrails.org/mailman/listinfo/rails

 @public_topics=PublicTopic.find_by_sql("select * from public_topics
where category='" + params[:id] + "'" )

This line is overwriting the paginated array of objects with all objects
that match the category.  I suggest deleting this line and using

@public_topic_pages, @public_topics = paginate(:public_topics,
:per_page=>2, :conditions=>["category = ?",params[:id])


_Kevin
This topic is locked and can not be replied to.