ruby ActionController::RoutingError(没有路由匹配 [GET] "/"):
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23194386/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ActionController::RoutingError (No route matches [GET] "/"):
提问by kaizenCoder
I'm playing around with a tutorial which uses unicorn and rails. I'm completely new to rails and for the purpose of the tutorial all I've done for the project is bundle exec rails new rails-starterwith no further app modifications.
我正在玩一个使用独角兽和导轨的教程。我是 Rails 的新手,出于本教程的目的,我为该项目所做的所有工作都bundle exec rails new rails-starter没有进一步修改应用程序。
When I run bundle exec unicorn -c config/unicorn.rb -E productionI get the message in the browser:
当我运行时,bundle exec unicorn -c config/unicorn.rb -E production我在浏览器中收到消息:
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
The page you were looking for doesn't exist.
You may have mistyped the address or the page may have moved.
The log shows:
日志显示:
ActionController::RoutingError (No route matches [GET] "/"):
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/railties-4.0.4/lib/rails/rack/logger.rb:38:in `call_app'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/railties-4.0.4/lib/rails/rack/logger.rb:20:in `block in call'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/tagged_logging.rb:68:in `block in tagged'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/tagged_logging.rb:26:in `tagged'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/tagged_logging.rb:68:in `tagged'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/railties-4.0.4/lib/rails/rack/logger.rb:20:in `call'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/request_id.rb:21:in `call'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/activesupport-4.0.4/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/railties-4.0.4/lib/rails/engine.rb:511:in `call'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/railties-4.0.4/lib/rails/application.rb:97:in `call'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:572:in `process_client'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:666:in `worker_loop'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:521:in `spawn_missing_workers'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/unicorn-4.8.2/lib/unicorn/http_server.rb:140:in `start'
/home.rbenv/versions/2.0.0-p0/lib/ruby/gems/2.0.0/gems/unicorn-4.8.2/bin/unicorn:126:in `<top (required)>'
/home.rbenv/versions/2.0.0-p0/bin/unicorn:23:in `load'
/home.rbenv/versions/2.0.0-p0/bin/unicorn:23:in `<main>'
However if I just run the rails app via bundle exec rails serverI can successfully access via [IP]:3000
但是,如果我只是通过运行 rails 应用程序,bundle exec rails server我可以通过以下方式成功访问[IP]:3000
I suspect the error is something to do with ActionController::RoutingError (No route matches [GET] "/"):however I lack the rails knowledge to figure out the fix.
我怀疑该错误与此有关,ActionController::RoutingError (No route matches [GET] "/"):但是我缺乏 Rails 知识来找出修复方法。
回答by Lenin Raj Rajasekaran
You need to setup a root route in routes.rbfile.
您需要在routes.rb文件中设置根路由。
root :to => 'index#index'
Where the first index is the controller name (IndexController) and the second index is the action name in the IndexController.
其中第一个索引是控制器名称 (IndexController),第二个索引是 IndexController 中的操作名称。

