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

Problem with register users

Hi, I try to learn something about Rails and follow the Treebook tutorial. I've come to that stage when we install devise. And devise is installed with no problems. and I can register a new user without a problem. But I always get a error message "undefined method `full_name' for nil:NilClass"

app/views/statuses/index.html.erb:9:in `block in _app_views_statuses_index_html_erb___3166094988121289217_70208237682380'
app/views/statuses/index.html.erb:5:in `_app_views_statuses_index_html_erb___3166094988121289217_70208237682380'

And I've try to solve this problem by my self, and I had try to delete all statuses & Users multiple times, without success.

When I do Rails c -> U = User.First I get following code.

irb(main):001:0> U = User.first
  User Load (0.2ms)  SELECT "users".* FROM "users" ORDER BY "users"."id" ASC LIMIT 1
=> #<User id: 4, first_name: nil, last_name: nil, profile_name: nil, email: "john@john.com", encrypted_password: "$2a$10$E3O/AblpU7jYgPFU.qEeWuo7uSPABnaCQoKL2UgOWtvJ...", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, current_sign_in_at: "2013-09-14 11:45:18", last_sign_in_at: "2013-09-14 11:45:18", current_sign_in_ip: "127.0.0.1", last_sign_in_ip: "127.0.0.1", created_at: "2013-09-14 11:45:18", updated_at: "2013-09-14 11:45:18">

It seems like devise don't register full name, last name & profile name ?! Can this be the problem and how do I fix it?

Aron,

Which stage are you on?

The full_name method is not one that's defined in Stage 3 so maybe you want first_name?

First_name doesn't work either. I'm on Creating an Authentication System but the problem started showing up when installed simple_form

this is my user.rb file

class User < ActiveRecord::Base

# Include default devise modules. Others available are: # :confirmable, :lockable, :timeoutable and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable

attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :profile_name # attr_accessible :title, :body

has_many :statuses

def full_name first_name + " " + last_name end

end

1 Answer

Alan Johnson
Alan Johnson
7,625 Points

So the error "undefined method X for nil:NilClass" pretty much always guarantees that you're calling a method on nil that you're meaning to be calling on an object. In this case you're calling full_name on nil. Since it's happening in your view, that probably means that you're not logged in, but I'll need to see your view code to know for sure.