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

undefined method `full_name' for nil:NilClass

while I was following this tutorial, 'Creating Relationships', I encountered with this error. status.rb and user.rb with all of html.erb files are the same with the project files included in the tutorial. I cannot figure out where the cause of error is located in..!

10 Answers

rails console then Status.delete_all worked !

Nicholas Fox
Nicholas Fox
5,520 Points

I was stumped by the same error for a while. I kept clearing all statuses and users from the database using the rails console, then generating a new user and new statuses. I still would receive this same error message.

The issue was I was providing an incorrect user_id.

When you "sign up" for the site, look in the command prompt window and find the message associated with adding a new user to the database (you may have to scroll up). Near the end of that message, it will tell you the user_id associated with that user. Try plugging that in when writing a status. That fixed the problem for me!

Thanks! This one fixed it for me too! I was posting the status under id 1 (as per the tutorial video), when in actual reality my id was 4. Great advice!

Can you please show us the error you got?

I apologize for the absence of the error display...

NoMethodError in Statuses#index

Showing c:/Projects/treebook/app/views/statuses/index.html.erb where line #10 raised:

undefined method `full_name' for nil:NilClass Extracted source (around line #10):

7: 8: <% @statuses.each do |status| %> 9: <div class="status"> 10: <strong><%= status.user.full_name %></strong> 11: <p><%= status.content %></p> 12: <div class="meta"> 13: <%= link_to time_ago_in_words(status.created_at) + " ago", status %> Rails.root: c:/Projects/treebook

Application Trace | Framework Trace | Full Trace app/views/statuses/index.html.erb:10:in block in _app_views_statuses_index_html_erb___1060382079_28817352' app/views/statuses/index.html.erb:8:ineach' app/views/statuses/index.html.erb:8:in _app_views_statuses_index_html_erb___1060382079_28817352' app/controllers/statuses_controller.rb:7:inindex' Request

Parameters:

None

I'm stuck on the exact same problem, any suggestions would be great :) thanks

I fixed this problem!

Shawn Miller
Shawn Miller
3,688 Points

how?? :/ I'm having the exact same thing.

I' m receiving this same error and its frustrating me to no end!! I believe I'm getting it because I don't have a value set for the "first_name" or "last_name" variables. How can I set a value to get rid of the error??

Shawn Miller
Shawn Miller
3,688 Points

I'm having the same issue... any fixes??

wow, same error here. An explanation on how to fix it would be obviously great.

markuslopez
markuslopez
371 Points

did you ever get a response? having the same issue!

Im having the same issue as well. Clearing all data in the rails console does not fix the problem.

markuslopez
markuslopez
371 Points

did you ever get a response? having the same issue!

I;m having the same issue and have tried everything i can find anywhere HELP PLEASE!!!

markuslopez
markuslopez
371 Points

did you ever get a response? having the same issue!

Indrek Vainu
Indrek Vainu
548 Points

I had the problem that this line

<li><%= link_to current_user.full_name, "#" %></li>

in my layouts/application.html.erb caused a undefined method error.

what helped was that I deleted all my users and statuses from the database. I used DB Browser for SQLite program for that, simple to use and the graphical interface for me at least gives a better overview .

After deleting all the statuses and users, I added a new user via sign_up and a new status and then this line

<li><%= link_to current_user.full_name, "#" %></li>

did not give any errors and my full name was displayed top right as the name of the person currently logged in.