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

undefined method `user' for #<Status:0x007fddb6f656a8>

This is the error I'm getting when I post a status. The status actually goes through, but the /statuses/(status id) page gives me an error

The video and everything I read said to do this:

<p id="notice"><%= notice %></p>

<p>
  <strong>Name:</strong>
  <%= @status.user.first_name %>
</p>

<p>
  <strong>Content:</strong>
  <%= @status.content %>
</p>

<%= link_to 'Edit', edit_status_path(@status) %> |
<%= link_to 'Back', statuses_path %>

Which returned an error.

I changed it to this:

<p id="notice"><%= notice %></p>

<p>
  <strong>Name:</strong>
  <%= current_user.first_name %>
</p>

<p>
  <strong>Content:</strong>
  <%= @status.content %>
</p>

<%= link_to 'Edit', edit_status_path(@status) %> |
<%= link_to 'Back', statuses_path %>

And it worked, so what's the deal here. Does this mean that any user that's logged in, it will only display their name?

Here is the GitHub link https://github.com/ausgates/treebook

1 Answer

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

I downloaded your code and deployed it locally and everything works fine. It only shows errors when you don't apply any user to the status. Maybe you should reset your database just in case (rake db:reset).

Shortly after posting this I again went into console, deleted all of the statuses and reset the DB and everything worked. I had tried this before but maybe missed a step. Thanks for your answer anyways! :)