0

我正在使用 Michael Hartl 教程。在第 7 章中,我发现了启动服务器并运行时显示的问题

http://localhost:3000/signup

我收到这条消息:

 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'

有什么想法吗?

4

2 回答 2

1

@user可能没有被实例化。users_controller.rb在方法中检查您是否有def new类似@user = User.new.

于 2012-09-27T19:45:20.233 回答
0

做就是了

@user = User.new

当您使用尚未定义的变量时会出现这种类型的错误

于 2012-09-28T06:02:07.603 回答