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

Generating the Devise Views: NoMethodError in Devise/registrations#new

I have been following along just fine up until this point. As this video started I generated the devise views without a problem using rails generate devise:views.

I then open up the file app/views/devise/registrations/new.html.erb

I added the 3 lines for first_name, last_name, and profile_name to the top of the file just like Jason does using the text_field form field for each of them. I checked this part carefully for typos several times.

I then saved the file, started the server, and went to the sign_up page and noticed that it says I am already signed in so I tried in a different browser. When I go to the url http://localhost:3000/users/sign_up in a different browser I get the following error message:

NoMethodError in Devise/registrations#new

undefined method `first_name' for #<User:0x31e3438>

Extracted source (around line #7):

4: <%= devise_error_messages! %> 5: 6: <div><%= f.label :first_name %><br /> 7: <%= f.text_field :first_name %></div> 8: 9: <div><%= f.label :last_name %><br /> 10: <%= f.text_field :last_name %></div>

Just trying some things, I changed all 3 of them from text_fields to password_fields and the form loads just fine.

I also downloaded the project code and replaced my code. Still the same error.

I am using the latest versions of everything and I am on a Windows 7 platform.

If anyone knows what could be going on please let me know.

9 Answers

Kerel Lacy
Kerel Lacy
8,474 Points

Did you migrate your db?

Kerel Lacy
Kerel Lacy
8,474 Points

I'm pretty sure I also remember those fields get replaced with other instance variable if you keep watching.

Yes the first thing I did was migrate my db. Yeah I would keep watching, but I want to get this working before I move on. It most likely has something to do with a Ruby version, Rails version, or my system setup. I even went back and started from the first video again and I am still getting the same error at that part.

Kerel Lacy
Kerel Lacy
8,474 Points

Ah I see yeah, Brett keep watching and Jim will migrate his db and will run into the same errors and from there explains how to get around these errors.

Alright, I will give it a try and hopefully fix the error so I can go back and follow along with him.

Could you please let me know what section he runs into errors.

Kerel Lacy
Kerel Lacy
8,474 Points

I'm pretty sure it's generating devise views

I took the code from stage 2 and started stage 3 fresh again and did not run into the problem. I wish I found out what it was, but at least I can move on now. Thanks for the help!

I am having similar problem on stage 3

NoMethodError in Devise::Registrations#new

Showing C:/Sites/treebook/app/views/devise/registrations/new.html.erb where line #8 raised: undefined method `lastname' for #<User:0x2a46b18>

Extracted source (around line #8):5 6 7 8 9 10 11 <%= f.text_field :firstname %></div>

<div><%= f.label :lastname %><br />
<%= f.text_field :lastname %></div>

<div><%= f.label :profile_name %><br />
<%= f.text_field :profile_name %></div>

Rails.root: C:/Sites/treebook