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 Build a Simple Ruby on Rails Application Creating an Authentication System Generating the User Model

David Langley
David Langley
10,965 Points

Localhost:3000 wont load "NoMethodError in Statuses#index"

When trying to load my localhost:3000 i get an error that states

undefined method `each' for nil:NilClass

the line it references in my code is;

<% @Statuses.each do |status| %>

This is preventing the localhost page from loading.

any ideas on how i can fix this problem ? hope you can help.

4 Answers

do you have

@statuses = Status.all 

In your statuses_controller?

David Langley
David Langley
10,965 Points

Andrew,

Status controller looks to be intact, it reads; # GET /statuses # GET /statuses.json def index @statuses = Status.all end

Nick Fuller , I showed a typo there i did have it at lower case (sorry!)

Nick Fuller
Nick Fuller
9,027 Points

Your instance variable is capitalized.

@Statuses.each do |status|

I think you want

@statuses.each do |status|
David Langley
David Langley
10,965 Points

errrr.... now I am having trouble even getting the rails server started. error is saying;

/Users/chickenguts/.rvm/gems/ruby-1.9.3-p484/gems/activemodel-4.0.3/lib/active_model/deprecated_mass_assignment_security.rb:14:in attr_accessible':attr_accessibleis extracted out of Rails into a gem. Please use new recommended protection model for params(strong_parameters) or addprotected_attributes` to your Gemfile to use old one. (RuntimeError)

any ideas guys ?

That specific error sounds like it's asking you to use strong params. A big difference between Rails 4 and rails 3.2 (which is what I believe they use in the video) is Rails 4 requires you declare strong parameters as opposed to using attr_accessible like they do in the video.

To declare a strong param, you need to do it at the bottom of your statuses controller as a private method. Ex:

def status_params
      params.require(:status).permit(:user_id, :content)
    end