szatan
szatan

Reputation: 517

Rails Tutorial, chapter 7 undefined method "model_name"

I'am working with Michael Hartl Tutorial. In chapter 7 I've found problem that I shows when I start server and run

http://localhost:3000/signup

I recive this message:

 NoMethodError in User#new

 Showing C:/rails_project/sample_app/app/views/user/new.html.erb where line #6 raised:

 undefined method `model_name' for NilClass:Class

 Extracted source (around line #6):

 3: 
 4: <div class="row">
 5:   <div class="span6 offset3">
 6:     <%= form_for(@user) do |f| %>
 7: 
 8:       <%= f.label :name %>
 9:       <%= f.text_field :name %>

 Rails.root: C:/rails_project/sample_app
 Application Trace | Framework Trace | Full Trace

 app/views/user/new.html.erb:6:in `_app_views_user_new_html_erb___578921578_24443340'

Got any idea?

Upvotes: 0

Views: 148

Answers (2)

Aayush Khandelwal
Aayush Khandelwal

Reputation: 1071

Just do

@user = User.new

this type of error come when you are using a variable which has not been defined yet

Upvotes: 0

MurifoX
MurifoX

Reputation: 15089

The @user is probably not being instantiated. Check you users_controller.rb in the def new method for something like @user = User.new.

Upvotes: 1

Related Questions