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


NoMethodError in Statuses#index

Struggling on creating the User ID and showing it as a Name.

When I load the site I can sign up ok, I can create a status on but the next page gives me the following error... NoMethodError in Statuses#show

/app/views/statuses/show.html.erb where line #5 raised:

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

2: 3: <p> 4: <b>Name:</b> 5: <%= @status.user.full_name %> 6: </p>

Also when I try and show the User ID field where I can input the user ID number on this page I get an error. I have a relationship problem with the database I think? I see lots of other people are having issues on this section so maybe it is not explained efficiently as I've been through all the videos several times.

When I try rake bd:migrate I get the following

AddDeviseToUsers: migrating =============================================== -- change_table(:users) rake aborted! An error has occurred, this and all later migrations canceled:

SQLite3::SQLException: duplicate column name: first_name: ALTER TABLE "users" ADD "first_name" varchar(255)/usr/local/rvm/gems/ruby-1.9.3-p392/gems/sqlite3-1.3.7/lib/sqlite3/database.rb:91:in `initialize'

What is wrong?

4 Answers

Itay Banner
Itay Banner
1,922 Points

Well, using rake db:reset did the trick for me too. I'm guessing that it has something to do with our "old" user inconsistent with how it should be setup under "Devise". Anyway, +1 on the need to clarify why this happened.

EDIT: Ok, I feel stupid. Jim actually refers to this error a bit around 07:10 in the video :-)

Jon Hockley
Jon Hockley
3,781 Points

Aha! Now I see it.

Just incase anyone is still a little confused with this, it's because we're trying to output the id or name (depending on what you had to output) for a status that doesn't yet have a user ID associated with it. We can't output something that doesn't exist.

rake db:reset

Will sort out the issue because it will remove all statuses, so when you enter new ones, they will have ID's associated with them. Or you could just do what Jim does in the video and delete the statuses you know haven't got anything associated with them just yet.

Hope this clears it up for anyone who got stuck as long as I did getting such a simple concept understood when faced with that error!

Jon Hockley
Jon Hockley
3,781 Points

I'm stuck here, too. Was just about to post the same topic before seeing yours.

Here is my status model:

class Status < ActiveRecord::Base
  attr_accessible :content, :user_id
  belongs_to :user

And here is my erb tag in show.html.erb

<%= @status.user.first_name %>

Any help would be awesome.

Jon Hockley
Jon Hockley
3,781 Points

After digging around in the forum, I managed to get it working. I'm not sure about you, Nick, you may have futher issues with your code because I didn't change any of mine.

I used the command:

rake db:reset

After running that, all my data was gone but I didn't get the error once I had created a new status, it showed my user OK.

It would still be good to hear from someone as to why I had to do this and Jim didn't in the video?

Hope this helps you.

rake db:reset also did the trick for me.