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 Build a Simple Ruby on Rails Application Customizing Forms Creating Relationships

User status relationship bug

Followed the video exactely, but still manage to get this error, whatever user_id I use.

NoMethodError in Statuses#show
Showing C:/Sites/treebook2/app/views/statuses/show.html.erb where line #4 raised:

undefined method `first_name' for nil:NilClass 

I've kind of narrowed down the bug to the fact that when signing up, the user is still not getting a first name or last_name assigned to them

Github page

5 Answers

Yup, the problem was the version of Ruby I was using at the time. This appears to be a common problem with people following that tutorial. Would be nice if treehouse could put up a note telling you that it is in Ruby 3.2 and that using Ruby 4.0+ will cause problems, or hell updating the tutorial would be great.

Lisa Rossiter
Lisa Rossiter
3,630 Points

You need push your app to git hub :)

Lisa Rossiter
Lisa Rossiter
3,630 Points

You know you mentioned that first and last name are not getting assigned. Have you checked that your strong parameters for devise are updated accordingly. Check out the devise strong parameters documentation and you need to put it in your application.rb. If you push an update to git hub I can check for you

Seph Cordovano
Seph Cordovano
17,400 Points

If it helps, my application controller finally looked like this (which goes along with what Lisa is saying) after quite a number of hours of debugging this is issue and not much help from the Treehouse forums.

app/controllers/application_controller.rb

class ApplicationController < ActionController::Base
before_filter :update_sanitized_params, if: :devise_controller?

   protect_from_forgery with: :exception 

end

def update_sanitized_params
  devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:profile_name, 
    :email, :first_name, :last_name, :password) }
end
Lisa Rossiter
Lisa Rossiter
3,630 Points

When you go to edit a user is their names in the fields?

Lisa Rossiter
Lisa Rossiter
3,630 Points

Also your github is still not up to date?

for example your show page is still

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

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

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

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

Welp, guys it appears that the problem is that I'm using Ruby 4.1, while the tutorial videos use Ruby 3.2. I'm going to uninstall everything and start fresh but with Ruby 3.2 and see how it goes.