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

Hi, I am on the treebook exercise where we add the following to the bottom of _form.html.erb

<%= f.input :user_id %>

When I go back to treebook and try to edit a status or post a new one, I get the following error message.

NoMethodError in Statuses#new 

Showing C:/Users/RockyRoad/Desktop/Austin/practice/Project/treebook/app/views/statuses/_form.html.erb where line #14 raised:

undefined method `user_id' for #<Status:0x3342fc0>

Extracted source (around line #14): 11: </div> 12: <% end %> 13: <br> 14: <%= f.input :user_id %> 15: <%= f.input :content %> 16: <div class="form-actions"> 17: <%= f.button :submit %>

Thanks for the help. -Austin

1 Answer

I'm taking a guess here. You need to delete all your statuses because when we first made statuses, there was no user_id. So your database has some old data with no user_ids.

To do this, in your terminal, type:

rails console

That allows you to get access to your database. Then delete the statuses by using:

Status.delete_all

And before you do that, I recommend looking at:

Status.first

You should notice that the user_id column is empty. This is why you are getting the error. Likewise, you could look at:

Status.last

This should have a user_id if you recently created a status.

If none of this is the case, then we need you to paste some of your code, particularly from _form.html.erb and your statuses controller so we can help you figure out what is wrong.