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 trialGuled A.
10,605 PointsCreating Relationships Problems [Rails 4.1.1]
I've been doing some research before requesting help from the forums, but I cannot quite find the solution to my problem. I currently have problems implementing the first name and last name in the index page as well as the 'show' page. Adding code in the following pages:
[index.html.erb]
<strong><%= status.user.first_name %></strong>
[show.html.erb]
<%= @status.user.first_name %>
seems to be, repeatedly, causing this error to appear:
undefined method `first_name' for nil:NilClass
I decided to do some research on the forums afterwords and found this piece of information, but it did not help:
[statuses_controller.rb]
def status_params
params.require(:status).permit(:name, :content, :user_id)
end
I also looked at a Devise controller mentioned by Jason, but I do not know what to do with the piece of code provided. Do I simply make a Devise controller and put it in the "Controller" directory or is there something else to it?
Either way, I am stuck with adding the users first name let alone their last. Can anyone guide me through this problem?
Guled A.
10,605 Pointsundefined method `first_name' for nil:NilClass
1 Answer
Guled A.
10,605 PointsYou know what. I'm going to follow each track with it's exact version. Close this thread.
David Curtis
11,301 PointsDavid Curtis
11,301 Pointswhat happens when you make it just @user.first_name?