找到了类似的帖子here,但我正在运行Mac,因此第一个解决方案并不完全适用,第二个解决方案对我不起作用。
使用ruby 1.9.3p0(2011-10-30修订版33570)运行Mac OS 10.7.2,Xcode 4.2.1,rvm 1.10.1 [x86_64-darwin11.2.0]
我相信rvm的问题,但我不知道如何解决它
$ 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 >
我关注的是The Rails 3 Way
同样,我相信rvm的问题,但我不知道如何解决它?
更新: 也许它与rvm没有关系,运行本机Ruby 1.8.7和Rails 3.1.3我遇到了同样的问题:
>> ActionController::Dispatcher.new.call(env).last.body
NameError: uninitialized constant ActionController::Dispatcher
from (irb):6
答案 0 :(得分:2)
看看config.ru,在我看来是:
> 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生成文件,并将其更改为我们的本地名称。
我将它用于我的应用程序(Rack :: Test):
def app
Wagn::Application
end
请注意,没有'.new',因为此类是应用程序,而不是中间件。
答案 1 :(得分:1)
看起来ActionController::Dispatcher
只是在你正在使用的rails版本中不存在。如果您关注一本书,通常最好坚持使用本书的Rails版本。