我正在使用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'
知道吗?
答案 0 :(得分:1)
@user
可能未被实例化。在users_controller.rb
方法中检查def new
是否有@user = User.new
之类的内容。
答案 1 :(得分:0)
只做
@user = User.new
当您使用尚未定义的变量
时会出现此类错误