Skip to content

Instantly share code, notes, and snippets.

@travisdmathis
Created September 2, 2012 13:11
Show Gist options
  • Save travisdmathis/3598642 to your computer and use it in GitHub Desktop.
Save travisdmathis/3598642 to your computer and use it in GitHub Desktop.
### ERROR ###
undefined method `each' for nil:NilClass
### /views/posts/_latest.html ###
<table>
<tr>
<th>Name</th>
<th>Title</th>
<th>Content</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @posts.each do |post| %>
<tr>
<td><%= post.name %></td>
<td><%= post.title %></td>
<td><%= post.content %></td>
</tr>
<% end %>
</table>
### /views/layouts/application.html.erb ###
<%= render 'posts/latest' %>
### /app/controller/posts_controller.rb ###
def index
@posts = Post.all
respond_to do |format|
format.html # index.html.erb
format.json { render :json => @posts }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment