为什么我的开发服务器无法加载? default_controller_and_action':缺少:action(ArgumentError)

发布于 2024-10-09 16:20:15 字数 7276 浏览 0 评论 0原文

我是 Ruby nuby(也是 Stack Overflow 的新手),致力于 Michael Hartl 的 Rails 教程 突然我的开发服务器 无法加载并不断退出。控制台也不会加载,并且 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$ 

I'm a Ruby nuby (and new to Stack Overflow) working on the Rails Tutorial by Michael Hartl and all of a sudden my development server won't load and keeps exiting. Console also won't load and Rspec spec/ produces errors/exceptions. I am including some output from the terminal, your help is much appreciated.

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$ 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

在梵高的星空下 2024-10-16 16:20:15

当我遇到这个问题时,这是因为 routes.rb 中的其中一条路由有斜杠 (/) 而不是哈希 (# >) 使用 controller#action 语法时(我使用了“controller/action”,这是不正确的)。

例如,我不小心有 root :to =>; '主页/索引'。它应该是 root :to =>; 'home#index'

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

When I ran into this problem, it was because one of the routes in routes.rb had a slash (/) instead of the hash (#) when using the controller#action syntax (I used "controller/action", which was incorrect).

For example, I accidentally had root :to => 'home/index'. It was supposed to be root :to => 'home#index'.

I found this solution in here.

纵性 2024-10-16 16:20:15

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

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

root :to => 'controller#action

This is caused by incorrect routes -
Please check your config/routes.rb , even if one route mentioned is wrong then this error is thrown !!
Also make sure that the route is

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

or

root :to => 'controller#action
非要怀念 2024-10-16 16:20:15

我也是一个 Ruby nuby,在研究 Michael Hartl 的 Rails 教程时也遇到了同样的错误。如果您像我一样,您可能只是在真正阅读或理解文本的情况下输入书中出现的所有代码。并不是所有事情都是一步一步来的。在演示驼峰式大小写与蛇式大小写时,Hartl 显示了一个包含以下代码的框。

$ rails generate controller static_pages ...

此处,Hartl 只是尝试对比使用蛇式大小写生成 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生成控制器static_pages ...”不确定这是否有任何效果,但现在一切正常。

I'm also a Ruby nuby and had the same error while working on the Rails Tutorial by Michael Hartl. If you're like me, you might be just typing in all code that appears in the book with really reading or understanding the text. Not everything is step by step. In demonstrating camel case vs. snake case Hartl shows a box with the following code

$ rails generate controller static_pages ...

Here, Hartl is simply trying to contrast instructions to generate a StaticPages controller using snake case, rather than camel case, which was done in Listing 3.4. The dots "..." are simply to edit out or truncate the rest of the instructions for the cmd line. I typed in exactly what was shown and wound up with the following in my routes file:

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

 get "static_pages/home"

 get "static_pages/help"

open up your routes file, delete

get "static_pages/..."

save the routes file, and try starting rails server again.

I also destroyed "rails generate controller static_pages ..." Not sure if that had any effect, but now everything works.

ㄖ落Θ余辉 2024-10-16 16:20:15

默认情况下,您会得到以下内容:

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'

By default you get this:

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

  get 'static_pages/home'

  get 'static_pages/help'

JUST ERASE THIS:

  get 'static_pages/...'

AND YOU WILL HAVE THIS IN THE ROUTES.RB FILE

Rails.application.routes.draw do

  get 'static_pages/home'

  get 'static_pages/help'
热情消退 2024-10-16 16:20:15

就我而言,这是由我的某些路由中的后缀斜杠“/”引起的。例如,

post 'load_query/'

删除此后缀后,

post 'load_query'

它就起作用了。

In my case it was caused by the suffix slash '/' in some of my routes. E.g.

post 'load_query/'

After removing this suffix to

post 'load_query'

it worked.

甜`诱少女 2024-10-16 16:20:15

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

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

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

change your default root in the routes.rb file.

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

I've gone through the same issue, and the above change worked for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文