Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Brian Goldstein
Brian Goldstein
19,419 Points

Generating the User Model: "undefined method 'each'

After installing devise, I'm able to go to localhost:3000/users/sign_up and create a new user, no problem. Yay! but, my status/index page now won't load. This is the error message I'm getting:

      Showing C:/Sites/Treebook/app/views/statuses/index.html.erb where line #7 raised:

undefined method `each' for nil:NilClass

Extracted source (around line #7):

4: 
5:  <%= link_to "Post a New Status", new_status_path, class:"btn btn-statuses" %>
6: 
7:  <% @success.each do |status| %>
8: <div class="status hover">
9:      <strong><%= status.name %></strong>
10:         <p><%= status.content %></p>

any ideas what to do?

2 Answers

Alan Johnson
Alan Johnson
7,625 Points

It looks like @success is nil. Should it be a different variable, like @statuses?

Brian Goldstein
Brian Goldstein
19,419 Points

Alan -

that was it. thanks!

to recap for posterity:

You must match the variable in your views/statuses/index.html.erb to the status controller file in order to avoid getting the Nil Class error.

Alan Johnson
Alan Johnson
7,625 Points

Awesome! Can you mark my answer as best answer so that it's helpful to other folks who bump into this in the future?