# Help with with displaying a selected list

**URL:** <https://www.ruby-forum.com/t/help-with-with-displaying-a-selected-list/82577>\
**Category:** Rails\
**Created:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/help-with-with-displaying-a-selected-list/82577 "2007-01-19T16:31:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [January 19, 2007, 4:31pm UTC](https://www.ruby-forum.com/t/help-with-with-displaying-a-selected-list/82577/1 "2007-01-19T16:31:28Z")

</div>

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

 \<% x = 0 %\> \<% for video in @videos %\> " %\> \<% else %\> \<%= "" %\> \<% end %\> \<% end %\>

| \<%= link\_to(image\_tag("videos/#{video.video\_thumbnail}", :size =\> '132x99', :border =\> 5, :id =\> 'thumbnail'), url\_for(:action =\> 'show', :id =\> video) ) %\>  
**Title:** \<%= h video.title %\>  
 \<% x = x + 1 %\> \<% if x % 2 == 0 %\> \<%= " |
|
| |

\<%= 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

[URIs, Addressability, and the use of HTTP GET and POST](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

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 25, 2007, 10:32pm UTC](https://www.ruby-forum.com/t/help-with-with-displaying-a-selected-list/82577/2 "2007-09-25T22:32:11Z")

</div>

removed\_email\_address@domain.invalid wrote:

> @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.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [September 25, 2007, 10:32pm UTC](https://www.ruby-forum.com/t/help-with-with-displaying-a-selected-list/82577/3 "2007-09-25T22:32:16Z")

</div>

Mohit S. wrote:

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