使用" rails生成脚手架时的NoMethodError"

时间:2014-05-09 20:14:18

标签: ruby-on-rails scaffolding nitrousio

我正在使用nitrous.io跟随Michael Hartl的Ruby on Rails教程。现在我试图使用scaffold命令并返回NoMethodError。我对编码很陌生,所以我不确定错误的原因,但这里到底发生了什么:

~/workspace/rails_projects/demo_app(master)$ rails generate scaffold User name:string email:string
/home/action/workspace/rails_projects/demo_app/config/environments/development.rb:1:in `<top (required)>': undefined method `configure' for #<DemoAppp::Application:0x007fa3572a63e8> (NoMethodError)
        from /home/action/.gem/ruby/2.1.1/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `require'
        from /home/action/.gem/ruby/2.1.1/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `block in require'
        from /home/action/.gem/ruby/2.1.1/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:214:in `load_dependency'
        from /home/action/.gem/ruby/2.1.1/gems/activesupport-4.0.5/lib/active_support/dependencies.rb:229:in `require'
        from /home/action/.gem/ruby/2.1.1/gems/railties-4.0.5/lib/rails/engine.rb:591:in `block (2 levels) in <class:Engine>'
        from /home/action/.gem/ruby/2.1.1/gems/railties-4.0.5/lib/rails/engine.rb:590:in `each'
        from /home/action/.gem/ruby/2.1.1/gems/railties-4.0.5/lib/rails/engine.rb:590:in `block in <class:Engine>'
        from /home/action/.gem/ruby/2.1.1/gems/railties-4.0.5/lib/rails/initializable.rb:30:in `instance_exec'
        from /home/action/.gem/ruby/2.1.1/gems/railties-4.0.5/lib/rails/initializable.rb:30:in `run'
        from /home/action/.gem/ruby/2.1.1/gems/railties-4.0.5/lib/rails/initializable.rb:55:in `block in run_initializers'
        from /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
        from /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
        from /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
        from /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
        from /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
        from /home/action/.gem/ruby/2.1.1/gems/railties-4.0.5/lib/rails/initializable.rb:44:in `each'
        from /home/action/.gem/ruby/2.1.1/gems/railties-4.0.5/lib/rails/initializable.rb:44:in `tsort_each_child'
        from /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/tsort.rb:411:in `call'
        from /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
        from /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
        from /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/tsort.rb:345:in `each'
        from /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/tsort.rb:345:in `call'
        from /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
        from /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
        from /home/action/.parts/packages/ruby2.1/2.1.1/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
        from /home/action/.gem/ruby/2.1.1/gems/railties-4.0.5/lib/rails/initializable.rb:54:in `run_initializers'
        from /home/action/.gem/ruby/2.1.1/gems/railties-4.0.5/lib/rails/application.rb:215:in `initialize!'
        from /home/action/workspace/rails_projects/demo_app/config/environment.rb:5:in `<top (required)>'
        from /home/action/.gem/ruby/2.1.1/gems/railties-4.0.5/lib/rails/application.rb:189:in `require'
        from /home/action/.gem/ruby/2.1.1/gems/railties-4.0.5/lib/rails/application.rb:189:in `require_environment!'
        from /home/action/.gem/ruby/2.1.1/gems/railties-4.0.5/lib/rails/commands.rb:44:in `<top (required)>'
        from bin/rails:8:in `require'
        from bin/rails:8:in `<main>'

对我而言,似乎由于某种原因,开发的路径.rb不是正确的,但我只是猜测。

1 个答案:

答案 0 :(得分:0)

这可能是由环境中的命名空间问题引起的。您的应用名为DemoAppp(请注意“p”),因此请确保您的命名惯例符合以下条件:

# app/config/initializers/development.rb
DemoAppp::Application.configure do

或者,如果DemoAppp可能拼写错误,您可能希望将DemoAppp替换为DemoApp 2 “p” 第