为什么我的开发服务器没有加载? default_controller_and_action':missing:action(ArgumentError)

时间:2010-12-31 05:33:20

标签: ruby-on-rails-3 action

我是一个Ruby nuby(也是Stack Overflow的新手),正在研究Rails Tutorial by Michael Hartl,突然之间我的开发服务器won't load and keeps exiting。控制台也不会加载和Rspec spec /产生错误/异常。我收到了终端的一些输出信息,非常感谢您的帮助。

Exiting
/Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:164:in `default_controller_and_action': missing :action (ArgumentError)
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:68:in `normalize_options!'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:51:in `initialize'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:261:in `new'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:261:in `match'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1112:in `match'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_dispatch/routing/mapper.rb:1297:in `match'
    from /Users/ameedachowdhury/rails_projects/railstutorial/config/routes.rb:11:in `block in <top (required)>'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:233:in `instance_exec'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/actionpack-3.0.3/lib/action_dispatch/routing/route_set.rb:233:in `draw'
    from /Users/ameedachowdhury/rails_projects/railstutorial/config/routes.rb:1:in `<top (required)>'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `block in load'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `block in load_dependency'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:596:in `new_constants_in'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:225:in `load_dependency'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.3/lib/active_support/dependencies.rb:235:in `load'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/application.rb:127:in `block in reload_routes!'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/application.rb:127:in `each'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/application.rb:127:in `reload_routes!'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/application.rb:120:in `block in routes_reloader'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.3/lib/active_support/file_update_checker.rb:32:in `call'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/activesupport-3.0.3/lib/active_support/file_update_checker.rb:32:in `execute_if_updated'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/application/finisher.rb:51:in `block (2 levels) in <module:Finisher>'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/application/finisher.rb:52:in `call'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/application/finisher.rb:52:in `block in <module:Finisher>'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `instance_exec'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/initializable.rb:25:in `run'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/initializable.rb:50:in `block in run_initializers'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `each'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/initializable.rb:49:in `run_initializers'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/application.rb:134:in `initialize!'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/application.rb:77:in `method_missing'
    from /Users/ameedachowdhury/rails_projects/railstutorial/config/environment.rb:5:in `<top (required)>'
    from /Users/ameedachowdhury/rails_projects/railstutorial/config.ru:3:in `require'
    from /Users/ameedachowdhury/rails_projects/railstutorial/config.ru:3:in `block in <main>'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rack-1.2.1/lib/rack/builder.rb:46:in `instance_eval'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rack-1.2.1/lib/rack/builder.rb:46:in `initialize'
    from /Users/ameedachowdhury/rails_projects/railstutorial/config.ru:1:in `new'
    from /Users/ameedachowdhury/rails_projects/railstutorial/config.ru:1:in `<main>'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rack-1.2.1/lib/rack/builder.rb:35:in `eval'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rack-1.2.1/lib/rack/builder.rb:35:in `parse_file'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rack-1.2.1/lib/rack/server.rb:162:in `app'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rack-1.2.1/lib/rack/server.rb:248:in `wrapped_app'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/rack-1.2.1/lib/rack/server.rb:213:in `start'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/commands/server.rb:65:in `start'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/commands.rb:30:in `block in <top (required)>'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/commands.rb:27:in `tap'
    from /Users/ameedachowdhury/.rvm/gems/ruby-1.9.2-p0@rails3tutorial/gems/railties-3.0.3/lib/rails/commands.rb:27:in `<top (required)>'
    from script/rails:6:in `require'
    from script/rails:6:in `<main>'
ameeda-chowdhurys-macbook:railstutorial ameedachowdhury$ 

6 个答案:

答案 0 :(得分:69)

当我遇到这个问题时,是因为routes.rb中的一个路由在使用{{1}时有一个斜杠(/)而不是哈希(#)语法(我使用“控制器/动作”,这是不正确的。)

例如,我偶然遇到controller#action。应该是root :to => 'home/index'

我在here找到了这个解决方案。

答案 1 :(得分:8)

这是由不正确的路线引起的 -
请检查你的config / routes.rb,即使提到的一条路线错了,也会抛出这个错误!!
还要确保路线

'/url/for/something' => 'controller#action'

root :to => 'controller#action

答案 2 :(得分:2)

我也是一个Ruby nuby,在使用Michael Hartl的Rails教程时遇到了同样的错误。如果你像我一样,你可能只是输入书中出现的所有代码,真正阅读或理解文本。并非一切都是一步一步的。在演示骆驼案例与蛇案例时,Hartl显示了一个包含以下代码的框

$ rails generate controller static_pages ...

在这里,Hartl只是试图对比指令以使用snake case而不是camel case来生成StaticPages控制器,这在清单3.4中已经完成。点“...”只是编辑或截断cmd行的其余指令。我在路线文件中输入了以下显示的内容并将其与以下内容联系起来:

SampleApp::Application.routes.draw do
 get "static_pages/..."

 get "static_pages/home"

 get "static_pages/help"

打开你的路线文件,删除

get "static_pages/..."

保存路由文件,然后再次尝试启动rails服务器。

我还销毁了“rails generate controller static_pages ...”不确定是否有任何影响,但现在一切正常。

答案 3 :(得分:1)

默认情况下你会得到:

Rails.application.routes.draw do
  get 'static_pages/...'

  get 'static_pages/home'

  get 'static_pages/help'

只是删除了这个:

  get 'static_pages/...'

你将在ROUTES.RB文件中拥有这个

Rails.application.routes.draw do

  get 'static_pages/home'

  get 'static_pages/help'

答案 4 :(得分:0)

在我的情况下,它是由我的一些路线中的后缀斜杠“/”引起的。 E.g。

post 'load_query/'

将此后缀删除后

post 'load_query'

它有效。

答案 5 :(得分:0)

更改routes.rb文件中的默认根目录。

get "static_pages#home"  TO root to: 'static_pages#home'

我经历过同样的问题,上述变化对我有用。