jimjohnlists-/E1597aS9LQAvxtiuMwx3w@public.gmane.org
2007-Jan-15 06:08 UTC
Help with with displaying a selected list.
Hello. I call a find_all_by_subject("action") which returns 2 videos and displays them properly. But when I add @video_pages, @videos paginate :videos, :per_page => 10 so I can paginate the videos, it displays ALL the videos as if I selected list videos. Can someone please tell me what I am doing wrong? Thank you. selectaction.rhtml <table> <tr> <% x = 0 %> <% for video in @videos %> <td><%= link_to(image_tag("videos/#{video.video_thumbnail}", :size => ''132x99'', :border => 5, :id => ''thumbnail''), url_for(:action => ''show'', :id => video) ) %><br> <b>Title:</b> <%= h video.title %><br> <% x = x + 1 %> <% if x % 2 == 0 %> <%= "</td></tr><tr>" %> <% else %> <%= "</td>" %> <% end %> <% end %> </tr> </table> <%= link_to ''Previous page'', { :page => @video_pages.current.previous } if @video_pages.current.previous %> <%= link_to ''Next page'', { :page => @video_pages.current.next } if @video_pages.current.next %> Controller class VideosController < ApplicationController def index list render :action => ''list'' end # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html) verify :method => :post, :only => [ :destroy, :create, :update ], :redirect_to => { :action => :list } def list @video_pages, @videos = paginate :videos, :per_page => 10 end def show @video = Video.find(params[:id]) end def new @video = Video.new end def create @video = Video.new(params[:video]) if @video.save flash[:notice] = ''Video was successfully created.'' redirect_to :action => ''list'' else render :action => ''new'' end end def edit @video = Video.find(params[:id]) end def update @video = Video.find(params[:id]) if @video.update_attributes(params[:video]) flash[:notice] = ''Video was successfully updated.'' redirect_to :action => ''show'', :id => @video else render :action => ''edit'' end end def destroy Video.find(params[:id]).destroy redirect_to :action => ''list'' end def selectaction @videos = Video.find_all_by_subject("action") @video_pages, @videos = paginate :videos, :per_page => 10 end end --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
jimjohnlists-/E1597aS9LQAvxtiuMwx3w@public.gmane.org wrote:> > Hello. I call a find_all_by_subject("action") which returns 2 videos > and displays them properly. But when I add @video_pages, @videos > paginate :videos, :per_page => 10 so I can paginate the videos, it > displays ALL the videos as if I selected list videos. Can someone > please tell me what I am doing wrong? Thank you. > > *snip* > > def selectaction > @videos = Video.find_all_by_subject("action") > @video_pages, @videos = paginate :videos, :per_page => 10 > endI think you need to put the conditions on the paginate request. In the 2nd line of the selectation action, your previous value of the variable "videos" is overwritten. I don''t have the syntax here, though. I''ll send it out later. I think it''s something like: @video_pages, @videos = paginate :videos, :per_page => 10, :conditions => ''subject = action'' Cheers Mohit. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mohit Sindhwani wrote:> > jimjohnlists-/E1597aS9LQAvxtiuMwx3w@public.gmane.org wrote: >> >> Hello. I call a find_all_by_subject("action") which returns 2 videos >> and displays them properly. But when I add @video_pages, @videos >> paginate :videos, :per_page => 10 so I can paginate the videos, it >> displays ALL the videos as if I selected list videos. Can someone >> please tell me what I am doing wrong? Thank you. >> >> *snip* >> >> def selectaction >> @videos = Video.find_all_by_subject("action") >> @video_pages, @videos = paginate :videos, :per_page => 10 >> end > > I think you need to put the conditions on the paginate request. In > the 2nd line of the selectation action, your previous value of the > variable "videos" is overwritten. > > I don''t have the syntax here, though. I''ll send it out later. I > think it''s something like: > @video_pages, @videos = paginate :videos, :per_page => 10, > :conditions => ''subject = action'' > > Cheers > Mohit.OK, here''s the example: @video_pages, @videos = paginate(:videos, :per_page => 20, :conditions => @condition, :conditions => [''subject = ?'', ''action''] ) Cheers Mohit. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---