Ruby on rails error

J

Jack Arnst

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: <table>
4: <tr>
5: <% x = 0 %>
6: <% for video in @videos %>
7: <td><%= 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

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

<br />

<%= link_to 'New video', :action => 'new' %>
 
I

Ilan Berci

Jack said:
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: <table>
4: <tr>
5: <% x = 0 %>
6: <% for video in @videos %>
7: <td><%= 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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,220
Messages
2,571,128
Members
47,744
Latest member
FrederickM

Latest Threads

Top