NameError: 未初始化的常量 ActionController::Dispatcher [英] NameError: uninitialized constant ActionController::Dispatcher
问题描述
在此处找到了类似的帖子,但我正在运行Mac,所以第一个解决方案并不完全适用,第二个对我不起作用.
Found a similar post here but I am running a Mac so the first solution does not exactly apply and the second didn't work for me.
使用 ruby 1.9.3p0 运行 Mac OS 10.7.2、Xcode 4.2.1、rvm 1.10.1(2011-10-30 修订版 33570)[x86_64-darwin11.2.0]
Running Mac OS 10.7.2, Xcode 4.2.1, rvm 1.10.1 using ruby 1.9.3p0 (2011-10-30 revision 33570) [x86_64-darwin11.2.0]
我认为问题是由 rvm 引起的,但我不知道如何解决
I believe the issue to due with rvm, however I do not know how to fix it
$ rails new dispatch_me
$ rails generate controller demo index
$ rails console
Loading development environment (Rails 3.2.0.rc2)
1.9.3-p0 :001 > env = {}
=> {}
1.9.3-p0 :002 > env['REQUEST_METHOD'] = 'GET'
=> "GET"
1.9.3-p0 :003 > env['PATH_INFO'] = '/demo/index'
=> "/demo/index"
1.9.3-p0 :004 > env['rack.input'] = StringIO.new
=> #<StringIO:0x007f946db0ece0>
1.9.3-p0 :005 > ActionController::Dispatcher.new.call(env).last.body
NameError: uninitialized constant ActionController::Dispatcher
from (irb):5
from /Users/rudolph9/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0.rc2/lib/rails/commands/console.rb:47:in `start'
from /Users/rudolph9/.rvm/gems/ruby-1.9.3-p0/gems/railties-3.2.0.rc2/lib/rails/commands/console.rb:8:in `start'
from /Users/rudolph9/.rvm/gems/ruby-1.9.3-p0/gems/railties- 3.2.0.rc2/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
1.9.3-p0 :006 >
我正在关注 Rails 3 Way
同样,我认为问题是由 rvm 造成的,但我不知道如何解决?
Again, I believe the issue to due with rvm, however I do not know how to fix it?
更新:也许它与 rvm 无关,运行本机 Ruby 1.8.7 和 Rails 3.1.3 我遇到了同样的问题:
UPDATE: Maybe it doesn't have something to do with rvm, running native Ruby 1.8.7 and Rails 3.1.3 I run into the same issue:
>> ActionController::Dispatcher.new.call(env).last.body
NameError: uninitialized constant ActionController::Dispatcher
from (irb):6
推荐答案
看看 config.ru,在我的情况下是:
Take a look at config.ru, in my case it is:
> cat config.ru
# This file is used by Rack-based servers to start the application.
require ::File.expand_path('../config/environment', __FILE__)
run Wagn::Application
该文件是使用 Main::Application 为 3.0 生成的,并已更改为我们的本地名称.
The file was generated for 3.0 with Main::Application and it was changed for our local name.
我将它用于我的应用程序 (Rack::Test):
I used this for my app (Rack::Test):
def app
Wagn::Application
end
注意没有.new",因为这个类是一个应用程序,而不是一个中间件.
Note there is no '.new', since this class is an application, not a middleware.
这篇关于NameError: 未初始化的常量 ActionController::Dispatcher的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!