Preview button causes an error in my code
It use to work great under rails 2 and now moving to rails 3 as caused开发者_JS百科 my code to have errors.
Error Message:
You have a nil object when you didn't expect it! You might have expected an instance of Array. The error occurred while evaluating nil.each
Slice of code:
<div id="archive-list">
<h4>Archives</h4>
<ul>
<% @archive_list.each do |item| -%>
<li><%= link_to(item[0], archive_url(:year => item[1], :month => item[2])) %></li>
<% end -%>
</ul>
there seems to be an issue with:
<% @archive_list.each do |item| -%>
with this line above
Any help would be great?
@archive_list
is probably nil
do a puts @archive_list
in the controller before rendering the view and check if it's nil
in the view you could do a <% if @archive_list.exists? %>
before iterating over it, if it's an active record relation, or <% if @archive_list.blank? %>
if it's something else (from the looks of the code it's the latter).
精彩评论