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

DELETE

DELETE

5 Answers

hey,

that's because you have old entries (statuses) that hadn't had a "first_name" or "last_name" value assigned when they were created, hence the value returned when asked for is "nil".

Simply remove the line <%= status.user.full_name%> from your viewfile, delete old statuses, and add it back in.

hope tha helps.

So I had this problem and struggled for hours trying to figure it out. My solution was to add Delete to the edit.html.erb page:

<%= link_to "Delete", @status, method: :delete, data: { confirm: "Are you sure your want to delete this status?"} %>

(don't forget the '@' symbol in front of status on this page, it is not the index.html.erb page)

Then make sure you've removed this line from both the show and index pages:

<%= status.user.full_name%>

Then change the route in the browser by hand:

http://localhost:3000/statuses/13/edit

in your case, you may need to change 13 to be [1, 2, ..., 13, ..., 15, ...] for however many statuses you've ever created.

You then delete each one.

Then go back in and create a new status. If you have the rest of the code up to date the dropdown box for user should show your "first name last name" (in my case, Sean Everett).

Note: this assumes that in your _form.html.erb file that you have this line:

<%= f.input :user_id, collection: User.all, label_method: :full_name %>

Create your new status, then add back this line to both show and index files: <%= status.user.full_name%>

Then refresh and you should no longer be getting an error.

The way I got to this was by visiting the actual github page for this step in the process and physically copying and pasting every file's code to make sure I hadn't mistyped (sometimes sublime text picks up weird blank spaces that may be causing issues with your code).

Hope this helps.

Thanks a lot Sean. I had the same problem and your solution helped a lot.

@Joona, not a problem man. This stuff can get extremely complex extremely quickly so I figured since Jason and Jim did such a great job of simplifying things, that I could help a little on my weird edge case.