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 Build a Simple Ruby on Rails Application Customizing Forms Creating Relationships

Issue with the Rails Facebook-like app

Once they added the devise and simple_form gems, things have gone horribly wrong. I keep getting errors when trying to display the users first and last name. I have added the relationships to both the users, using the has_many relationship between it and the statuses, and I added the relationship between the statuses and the users, with belongs_to. But I still have issues. I can already tell that this video is outdated, because they use attr_accessible, which isn't valid for the version of Rails that I am using. When I try to place that method in, I get an error for it. So what should I do now? Ask for a refund or just curse the creators of this site for not updating their videos?

At any rate.. The lines of ERB code that are placed in the index and form files are giving me problems. I inserted the following: <%= @status.user.first_name %> And I get the error message that the nil class doesn't have a method of first_name.
So this issue was addressed in the video, but the video's solution doesn't work for me.

3 Answers

I just figured out what was wrong. It turned out that during the course of watching the videos and playing with the site, I deleted many of the users ans statues. I recreated them once the fields for the first and last name where gone, and that caused the new users to have nil for their first_ and last_name values. Also, the statues didn't have a user_id value. I spent some time trying to figure out how to manually update those field. Once I did, everything worked.

If you are having the same issue, go into rails console you can update the fields within the table with this syntax:

var_name = Table_name.field_name = value

Not sure why it took me so long to figure it out, but I guess it was good practice. I guess I'm not so mad at treehouse anymore.

Thanks for your response Stone.

Stone Preston
Stone Preston
42,016 Points

Unfortunately those videos are indeed outdated. if you dont want to have any problems then I would just use the same versions of ruby, rails, and any gems that are used in the videos. theres no shame in doing that. If you want to use the new versions you can, but there will be quite a few issues.

There are some forum posts ( search treebook errors or something along those lines) where people have tips/suggestions for getting the new versions working but it is a struggle, but its always good to learn how to deal with issues like this.

The newer ruby projects (to do list) use Rails 4 and Ruby 2.0.0, so if you wanted to try those and use the newest version there is that too. To be honest I would start with the todo list. Its a much smaller and simpler project and you will have much fewer headaches. Then I would do treebook. Its definitely the hardest project on the site (even when it was current)

Oh, I should say, that if you have to fix the database through the rails console, after you set the fields, you need to save it. the syntax for that would be:

var_name.save