Ruby on Rails Thursday, March 26, 2015

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

On Thu, Mar 26, 2015 at 3:42 AM, Med Potter <medya.gh@gmail.com> wrote:
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| %>
    <tr>
      <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
end


and here is code for my view
$ cat  app/views/articles/index.html.erb
<h1>Listing articles</h1>

<table>
  <tr>
    <th>Title</th>
    <th>Text</th>
  </tr>

  <% @articles.each do |article| %>
    <tr>
      <td><%= article.title %></td>
      <td><%= article.text %></td>
    </tr>
  <% end %>
</table>
 
The code works for showing one article but not for showing all articles

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/c0e36d2f-8b86-4714-b2c1-d90beb9428ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAFKVRj-m-CwV5w5qnk--ud_AhApnNfrv0%3DKUGM_u3BO%2Bs7oEdA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment