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

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

  • TitleText

    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 ?

    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


    This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

    | Privacy Policy | Terms of Service | Remote Ruby Jobs