# Ruby on rails error

**URL:** <https://www.ruby-forum.com/t/ruby-on-rails-error/79376>\
**Category:** Ruby\
**Created:** [December 14, 2006, 5:26pm UTC](https://www.ruby-forum.com/t/ruby-on-rails-error/79376 "2006-12-14T17:26:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jack\_Arnst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/858c86/32.png) [@Jack\_Arnst](https://www.ruby-forum.com/u/Jack_Arnst)\
**Post date:** [December 14, 2006, 5:26pm UTC](https://www.ruby-forum.com/t/ruby-on-rails-error/79376/1 "2006-12-14T17:26:14Z")

</div>

The error and code is below. Any help would be greatly appreciated.

Error is

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occured while evaluating nil.each

Extracted source (around line #6):

3:

  
4:   
5: \<% x = 0 %\>  
6: \<% for video in @videos %\>  
7: 

| \<%= link\_to(image\_tag(“videos/#{video.video\_thumbnail}”,  
8: :size =\> ‘132x99’,  
9: :border =\> 5,

Controller is

def selectaction  
@video = Video.find :all  
end

View is

 \<% 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 %\>  
**Host:** \<%= h video.username %\>  
**Views:** \<%= h video.views %\>  
**Skill Level:** \<%= h video.rating %\>/10  
 \<% 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 %\>

  

\<%= link\_to ‘New video’, :action =\> ‘new’ %\>

 |

---

<div class="post-metadata">

**Author:** ![Jack\_Arnst](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/858c86/32.png) [@Jack\_Arnst](https://www.ruby-forum.com/u/Jack_Arnst)\
**Post date:** [December 14, 2006, 5:39pm UTC](https://www.ruby-forum.com/t/ruby-on-rails-error/79376/2 "2006-12-14T17:39:51Z")

</div>

Jack Arnst wrote:

> The error and code is below. Any help would be greatly appreciated.
> 
> Error is
> 
> You have a nil object when you didn’t expect it!  
> You might have expected an instance of Array.  
> The error occured while evaluating nil.each
> 
> Extracted source (around line #6):
> 
> 3:
> 
>   
> 4:   
> 5: \<% x = 0 %\>  
> 6: \<% for video in @videos %\>  
> 7: 
> 
> | \<%= link\_to(image\_tag(“videos/#{video.video\_thumbnail}”,  
> 8: :size =\> ‘132x99’,  
> 9: :border =\> 5,
> 
> Controller is
> 
> def selectaction  
> @video = Video.find :all  
> end
> 
> Jack,
> 
> Next time, please use the rails forum for posting rails related issues.
> 
> In this particular case, the instance variable in your controller is  
> “@video” while the variable you are trying to access in your view is  
> “@videos”. Change the name in your controller and everything should be  
> ok.
> 
> Hope this helps
> 
> ilan
> 
> |
