(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| %>

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

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*
    end

and here is code for my view

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

Listing articles

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

  • *
  •  <td><%= article.title %></td>*
    
  •  <td><%= article.text %></td>*
    
  • *
  • <% end %>*

  • Title Text

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

    http://localhost:3000/articles

    2 Possibilities.

    1. Did you run your migrations
    2. Did you restart your server after that ?

    On 25 March 2015 at 22:12, Med P. [email protected] wrote:

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

    class ArticlesController < ApplicationController
    def index
    @articles = Article.all

    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.

    Colin