(undefined method `each' for nil:NilClass) while doing Getting started tutorial

I followed every line of the tutorial

but I get this error

Showing /home/ubuntu/blog/app/views/articles/index.html.erb where line #9 raised:

undefined method `each’ for nil:NilClass

<% @articles.each do |article| %>

  <td><%= article.title %></td>
  <td><%= article.text %></td>

if you think that might not have returned the articles in the controller, thats not true :

here is code for my controller :

$ cat app/controllers/articles_controller.rb

class ArticlesController < ApplicationController

def index

** @articles = Article.all**


and here is code for my view

$ cat app/views/articles/index.html.erb

Listing articles

<% @articles.each do |article| %>

<% end %>

Title Text
<%= article.title %> <%= article.text %>

The code works for showing one article but not for showing all articles

2 Possibilities.

  1. Did you run your migrations

  2. Did you restart your server after that ?

To check that @articles is ok at this point then insert here puts @articles.inspect which will print the contents of @articles in the server terminal window.