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!
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

Adam Sackfield
Courses Plus Student 19,663 PointsLesson trouble. - Creating relashionships
Currently on this lesson and getting the following error - NoMethodError in Statuses#show Showing /home/action/treebook/app/views/statuses/show.html.erb where line #5 raised:
undefined method `first_name' for nil:NilClass
Extracted source (around line #5):
<p>
<strong>Name:</strong>
<%= @status.user.first_name %>
</p> Rails.root: /home/action/treebook I have deleted all statuses from rails console and all users and created new user and still getting this error. Any advice would be great as started the project again 3 times to ensure its not my error. Also a side note its hard to follow along as some things that you put in your files no longer valid now like the attr_accessible :content, :user_id when i enter this i get error message if i remove it i dont. Please advise.Thanks in advance Jim Hoskins Jason Seifer
4 Answers

Jason Seifer
Treehouse Guest TeacherAdam Flanagan here's how to change your rails version:
gem uninstall rails
gem install rails --version=3.2.16
If you're using rbenv do rbenv rehash
right after that. From there you should be able to follow along starting with the rails
command.

Brandon Barrette
20,485 PointsSo this means, either @status is nil, so therefore @status.user is nil, so you can't call full name on it. OR, there is no user_id on the status, so therefore calling @status.user returns nil (because there is no user).
I suggest going to the terminal. Go into rails console (type rails console).
Then try this and see what happens:
S = Status.last
S.user
S.user_id
S.user.full_name
What is the output for those 4 lines?

Adam Sackfield
Pro Student 19,663 PointsThanks so much for a response. I have started the project again and i'm almost at the same point now. If it fails again i will do those commands and post results.
Again thanks

Adam Sackfield
Pro Student 19,663 PointsI do have a question if you don't mind while i'm working my way back through again. lesson this lesson at 03:04 shows the users.rb file. It the version on the video it has the line starting attr_accessible blah blah, where as mine does not, why is this? Also when i add it nothing works so i leave it out? Any advice?

Brandon Barrette
20,485 PointsAre you using Rails 3.2? Attr_accessible tells rails which columns of the database you are allowed to write to. In rails 4 this moves out of the model and gets put somewhere else. If you are not using rails 3.2 I recommend using it because some things have changed and will not match the videos.

Adam Sackfield
Pro Student 19,663 PointsYeah i deleted by progress and was going to start again with Rails 3.2 today to see if it works then, which i assume it will.
Thanks

Jason Seifer
Treehouse Guest TeacherHey Adam Sackfield, Brandon Barrette is right -- the lessons are using 3.2 and not 4.0. The attr_accessible lines don't work in version 4.0. I recommend following along using Rails 3.2 since that is what the lessons use and will be the easiest way to keep track of everything in the videos.
Edit: Also, check out this video where Jim fixes a similar error. It may help.
As an aside, we're almost done with some Rails 4.0 content that should be out very soon :)

Josh Flowers
7,010 PointsI can't wait! I'm so stuck and just want to start over at this point.

Adam Flanagan
8,022 PointsJason Seifer does that mean I have to start from scratch? I've already done that 5 times and am getting really impatient! Please advise!!!

Adam Sackfield
Pro Student 19,663 PointsIf you are not using Ruby 1.9 and Rails 3.2 then you will have to start again Adam Flanagan

Adam Flanagan
8,022 PointsOkay, I'm about to start again, how do I change my rails version? Do I download the old version or what??

Adam Flanagan
8,022 PointsJason Seifer does that mean I have to start from scratch? I've already done that 5 times and am getting really impatient! Please advise!!!