Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Ruby

Build a Simple Ruby on Rails Application-Creating Relationships

Hi, I need help about Creating Relationships. When i follow the introduction on this part, i add has_many :statuses and belongs_to :user to each model, and finished the view part. However, when i run server it comes out "undefined method `first_name' for nil:NilClass" in show.html.erb file also the same problem in index file. I already used the Status.delete_all in console. it still don't work. Please advise

OK, I fixed it.

2 Answers

How did you fix this??!!

John Corser
John Corser
5,660 Points

did you figure out how he did it?

Hey, not sure if this will help but I was getting a similar problem. Heres a link to my posting where I posted how I fixed it. I was getting an error that said this: NoMethodError in Statues#show. "undefined method "full_name" for nil:NilClass. Hope that helps some!

https://teamtreehouse.com/forum/problem-with-devise-in-simple-ruby-on-rails-app

John Corser
John Corser
5,660 Points

This is exactly what I needed! Thanks for replying so quickly!

John Corser
John Corser
5,660 Points

Have you also had to use different bootstrap classes?

There are also a few steps that I didn't have to do, like deleting index.erb and setting accessible attributes to models.

Youre welcome! Glad it helped. Yeah I didn't have to do the attr_accessible part, not exactly sure what it does and any consequences of not doing it. Yeah had to use a few different class names in bootstrap as well. Just tried to find the equivalent on the bootstrap site lol. Good luck!

Yeah I am having that same problem, for me, when I go into my console and run User.all I see that my first_name, last_name, and profile_name have not been set (they are just nil). So I tried to delete the user and re-register but again I end up with nil for those three fields, maybe that has something to do with it and is a similar problem to what you're having