Welcome to the Treehouse Community
Looking to learn something new?
Julian McNeill9,444 Points
HELP!!! I keep getting undefined method `full_name' for nil:NilClass
I've entered everything right according to the lesson but i keep getting this error
Extracted source (around line #9): 6: 7: <% @statuses.each do |status| %> 8: <div class="status"> 9: <strong><%= status.user.full_name %></strong> 10: <p><%= status.content %></p> 11: <div class="meta"> 12: <%= link_to time_ago_in_words(status.created_at) + " ago", status %>
this is my second time starting from scratch. I don't understand what I entered wrong. can one of the teachers please help cause i'm stuck.
I think you don't have a user object to call the method full_name on. If there is no user object then the object you're calling the method full_name on is going to be nil. Which explains why you're getting a no method error for nil. Your full_name method is defined for your User class not Not Nil class.
Did you create a user, then create a status, then delete the user that created that status? I think this might work to get rid of the error but you would want to figure out why exactly this is happening.
Replace line 9 with this-
<%= status.try(:user).try(:full_name) %>
Not entirely sure you need that second try in there, try it both ways!
We can solve that by the following create migration to give first_name and last_name a default value of " ".
def full_name first_name.to_s + " " + last_name.to_s end
that because ruby will give you an error if you have "nil +". then we need to run "rails generate migration " in the terminal if you are using Mac or CMD in windows.