Bummer! You must be logged in to access this page.

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

Creating Relationships : Multiple Errors

This might be better off for 2 posts, since there are 2 distinct errors arising.

The first issue comes up at 3:11, where we're asked to add :name to the attr_accessible line in models/status.rb

For you, there is already attr_accessible :content. For me, there is nothing, and adding that information originally resulted in an error but not just simply doesn't display any status on any page.

To push through, I omitted the line " attr_accessible :content, :user_id " and everything was fine.

The second problem is when we started adding "first_name" and "last_name" everywhere. I immediately get the error:

NoMethodError in Statuses#index undefined method `first_name' for nil:NilClass

Playing around in the console, I took a look at the actualy database information of the only user, and discovered that Devise was not actually saving first_name, last_name, or profile_name. All the values were set to nil.

I decided to change "first_name" and "last_name" to things that did have values like "email" and "user_id", but I would get the same error.

I've reset the database and started fresh multiple times, but no luck. It may be a version difference (Ruby 2.0.0, Rails 4, Bootstrap 2.3.2, Simple Form 3.0.0.rc) between what you are using.

EDIT: Completed removed references to "first_name", "last_name", and "full_name" with "Filler Name" and now the content of the statuses aren't showing, and going into the console shows that the content isn't even being saved.

This is unbelievably frustrating. I've thrown so many things across the room.

4 Answers

I have the same issue and I can not find the issue on my my inputs are not saving to the database I have even ran tests and it still fails.

So I found a solution! Through some research, I found out that attr_accessor is somewhat deprecated in favor of something called Strong Parameters (not entirely sure what that means, but let's just role with it.

It required a few new files, and editing of the application controller, but I got it to work!

Follow the instructions here (thanks to 12 Spokes!). Scroll down to the "How To" section and follow it to a T (with the exception being you changes the specific parameters). In our case we need :first_name, :last_name, :profile_name, :password, and :password_confirmation.

When it comes to full name, change the method to: [first_name, last_name].join(" ")

Thanks man that was a great help

Thanks so much for this. This was super helpful!

Here is a screenshot of the error I'm getting.

No matter what I change "full_name" to, I get the same error. Removing the line entirely is the only way to fix it, which of course fixes nothing.

is your database up to date? it sounds like you may be needing to migrate your database.

Yes, I've done "rake db:reset" and "rake db:migrate" multiple times.