NameError: uninitialized constant ActionController::Dispatcher

匿名 (未验证) 提交于 2019-12-03 09:21:58

问题:

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.

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]

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 >  

I am following with the The Rails 3 Way

Again, I believe the issue to due with rvm, however I do not know how to fix it?

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 

回答1:

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 

The file was generated for 3.0 with Main::Application and it was changed for our local name.

I used this for my app (Rack::Test):

def app   Wagn::Application end 

Note there is no '.new', since this class is an application, not a middleware.



回答2:

It looks ActionController::Dispatcher just doesn't exist in the version of rails you're using. If your following a book it's usually best to stick with the version of Rails the book was written for.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!