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

Shawn Miller
Shawn Miller
3,688 Points

build a simple ruby on rails app

I believe I accidentally created a profile without a first and last name value earlier in development.

Now that I am trying to create a login system, it is giving me an undefined method "full_name" for nil:nilClass.

How do I go back and delete this empty profile? I'm kind of lost... :(

10 Answers

Shawn Miller
Shawn Miller
3,688 Points

I think I found a solution!

In another thread created by someone who encountered a similar error, I found this answer:

"I reset my databases (which deletes all of the statuses and accounts...so do this at your own risk haha because it worked for me, but I'm not sure if it'll work for you) by entering "rake db:drop rake db:create rake db:migrate" into terminal with the rails server turned off.

Note: you will need to go to /users/sign_up directly to create a new user before the index will work."

After I did this, I removed the

<ul class="nav pull-right">
<li><%= link_to current_user.full_name, "#" %></li>
</ul>

from the "treebook/app/views/layouts/application.html.erb" file, reloaded the localhost:3000/users/sign_up page, entered a new profile in, copied the

<ul class="nav pull-right">
<li><%= link_to current_user.full_name, "#" %></li>
</ul>

code back into the application.html.erb file, reloaded and BOOM!!! YAHH!!! signed in as the new user I just created HURRAY!!!!! YAAAAH!!!!

Stone Preston
Stone Preston
42,016 Points

hmm it doesnt sound like the profile you created would be causing the problem. Its been a long time since ive done that project, but some good tips for when you run into problems are rake your database and restart your server. what does the full_name method do? where do you call it? can you provide some more details.

Shawn Miller
Shawn Miller
3,688 Points

Hey Stone!

Thanks for taking the time again. I have tried raking my database and restarting my server.

I use the full_name method in the following places:

  • treebook/app/views/statuses/index.html.erb - in the <div class="status"> I use the tag
    <strong><%= status.user.full_name %></strong>

  • treebook/app/views/layouts/application.html.erb - in the navbar I use the tag <li><%= link_to current_user.full_name, "#" %></li>

I tried "Status.delete_all" in the rails console, but that caused me to get the same error when I tried to load the http://localhost:3000/statuses page which it didn't do before. I feel like I'm making things worse and I really don't have a good command of this programming language to solve my problem... :(

I'm pretty sure since I'm getting an "undefined method "full_name" for nil:nilClass." error that it has to do with the thing trying to pull a "full_name" where there isn't one. There is a stage earlier in the tutorial where you induce this error on purpose to show that you need to have the profile name defined properly, but I don't know what to do now. I used to have this error earlier before we used names and just used a user_id, and I had the user_id=1 that didn't have a name and it gave me this error, but I just got around it by saving the status with user_id=2 which had the name of "joe shmoe" that I gave it.

This wasn't an issue until we made this new update to the application.html.erb where the site is supposed to recognize the name of the person logged in. I think i'm logged in as user_id=1 and it's trying to recognize the full-name of this user that is not defined, hence the error. The problem is, I don't know how to delete user_id=1... :(

Sorry if this is confusing!!!

Shawn Miller
Shawn Miller
3,688 Points

ok, maybe I was premature..

This solution only seems to be working in an incognito window... I'll try and delete all my browser cache and see if that helps.

Shawn Miller
Shawn Miller
3,688 Points

ok... so even that doesn't work. Now I have NO IDEA why this solution would work in the incognito browser but not the other....... even after I've cleared all the cache.... I'm kinda lost here. HELP! :(

Shawn Miller
Shawn Miller
3,688 Points

ok... so even that doesn't work. Now I have NO IDEA why this solution would work in the incognito browser but not the other....... even after I've cleared all the cache.... I'm kinda lost here. HELP! :(

Shawn Miller
Shawn Miller
3,688 Points

OK! I think I have made progress.

I used the following code found thru stackoverflow:

<ul class="nav pull-right">
  <% if current_user %>
    <li><%= link_to current_user.full_name, "#" %></li>
  <% end %>
</ul>

AND BOOM! I stopped getting the error in my window! Praise be! :D

However, as the stackoverflow thing says, "This will display your link only when user is logged in (it means that current_user will return user instance, instead of nil)"

So now I will try and look at devise and see how I can determine whether I am logged in or not!

Shawn Miller
Shawn Miller
3,688 Points

Ok, I ran "rake routes" in the console.

If you go to localhost:3000/users/sign_in you can log in to accounts you have previously created.

However, when I go to localhost:3000/users/sign_out where you SHOULD be able to log out of your current session so that you can then log-in under another session..... I get the following error:

Routing Error

No route matches [GET] "/users/sign_out" Try running rake routes for more information on available routes.

whew..... I think it's bedtime for me now.

Liberty Montano
Liberty Montano
9,003 Points

Thank you! I was just about to scrap it and start over, and then this fixed it all. Thank you! Thank you!

John Steer-Fowler
PLUS
John Steer-Fowler
Courses Plus Student 11,734 Points

There is an easier way to do this.

Type 'rails console' in terminal. then type 'user = User.first' then simply type 'user.destroy'

Now you can create a new user on the sign_up page using the same details

Done.