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 %> <%= if @public_topic_pages.current.next link_to "Next >>", { :page => @public_topic_pages.current.next } end %> <hr> ------------------------------------------------------------- plz help me.... with regards, Arun. -- Posted via http://www.ruby-forum.com/.
On Tuesday, May 23, 2006, at 3:20 PM, Arunkumar Balu wrote:>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 %> ><%= if @public_topic_pages.current.next >link_to "Next >>", { :page => @public_topic_pages.current.next } >end %> ><hr> > >------------------------------------------------------------- > >plz help me.... > > >with regards, >Arun. > >-- >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 -- Posted with http://DevLists.com. Sign up and save your mailbox.
> From: Arunkumar Balu <arunkarthick.it@gmail.com>> 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..> 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...> > @public_topics=PublicTopic.find_by_sql("select * from public_topics > where category=''" + params[:id] + "''" )The problem is that you are overwriting the @public_topics in your controller. The second statement negates the pagination call made earlier. To solve it, use the conditions option in the paginate method . @public_topic_pages, @public_topics = paginate(:public_topics, :per_page=>2, :conditions => ''your condition here'') The above line should work. Hope that helps. Bharat
Thanx , now it works well... regards, Arun. On 5/23/06, Bharat Ahluwalia <bharata@aditi.com> wrote:> > > From: Arunkumar Balu <arunkarthick.it@gmail.com> > > > 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.. > > > 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... > > > > > @public_topics=PublicTopic.find_by_sql("select * from public_topics > > where category=''" + params[:id] + "''" ) > > The problem is that you are overwriting the @public_topics in your > controller. The second statement negates the pagination call made > earlier. > To solve it, use the conditions option in the paginate method . > @public_topic_pages, @public_topics = paginate(:public_topics, > :per_page=>2, :conditions => ''your condition here'') > > The above line should work. > > Hope that helps. > Bharat > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060524/5e6c2e30/attachment.html