当我尝试生成 Ruby on Rails 控制器时遇到的错误是什么?

发布于 2024-09-07 08:27:32 字数 2832 浏览 4 评论 0原文

我过去已经成功创建了控制器,但突然间我遇到了一个奇怪的错误。我正在这样做:

ruby script/generate controller Request

并且收到此错误消息:

/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/builder.rb:175:in `build': Illegal route: the :controller must be specified! (ArgumentError)
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:309:in `add_route'
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:317:in `add_named_route'
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:57:in `method_missing'
    from /Users/ben/rails_projects/talk/config/routes.rb:55
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:226:in `draw'
    from /Users/ben/rails_projects/talk/config/routes.rb:1
    from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in `load_without_new_constant_marking'
    from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in `load'
    from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in'
    from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in `load'
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:286:in `load_routes!'
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:286:in `each'
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:286:in `load_routes!'
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:266:in `reload!'
    from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:537:in `initialize_routing'
    from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:188:in `process'
    from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in `send'
    from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in `run'
    from /Users/ben/rails_projects/talk/config/environment.rb:9
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/generate.rb:1
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'

有关如何解决此问题的任何想法?感谢您的阅读。

I've created controllers in the past successfully, but all of a sudden I'm getting a weird error. I'm doing this:

ruby script/generate controller Request

And am getting this error message:

/usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/builder.rb:175:in `build': Illegal route: the :controller must be specified! (ArgumentError)
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:309:in `add_route'
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:317:in `add_named_route'
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:57:in `method_missing'
    from /Users/ben/rails_projects/talk/config/routes.rb:55
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:226:in `draw'
    from /Users/ben/rails_projects/talk/config/routes.rb:1
    from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in `load_without_new_constant_marking'
    from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in `load'
    from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in'
    from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:145:in `load'
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:286:in `load_routes!'
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:286:in `each'
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:286:in `load_routes!'
    from /usr/local/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:266:in `reload!'
    from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:537:in `initialize_routing'
    from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:188:in `process'
    from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in `send'
    from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/initializer.rb:113:in `run'
    from /Users/ben/rails_projects/talk/config/environment.rb:9
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
    from /usr/local/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/generate.rb:1
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
    from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'

Any ideas on how to fix this? Thanks for reading.

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

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

发布评论

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

评论(2

很酷不放纵 2024-09-14 08:27:32

我不确定它是什么,但你的 paths.rb 中的某些内容似乎导致了错误

I'm not sure what it is, but something in your routes.rb seems to be causing the error

囍孤女 2024-09-14 08:27:32

我相信 Request 是一个保留字,因此您可以将其用作控制器的名称。

您是否尝试过使用其他名称生成另一个控制器以查看是否出现相同的错误?

I believe Request is a reserved word and so you can use it as the controller's name.

Have you tried generating another controller with another name to see if the same error occurs?

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