ActionController::RoutingError(没有路由匹配 [GET] “/"): [英] ActionController::RoutingError (No route matches [GET] "/"):

查看:50
本文介绍了ActionController::RoutingError(没有路由匹配 [GET] “/"):的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在玩一个使用独角兽和导轨的教程.我是 Rails 的新手,出于本教程的目的,我为该项目所做的一切都是 bundle exec rails new rails-starter,没有进一步修改应用程序.

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-starter with no further app modifications.

当我运行 bundle exec unicorn -c config/unicorn.rb -E production 时,我在浏览器中收到消息:

When I run bundle exec unicorn -c config/unicorn.rb -E production I get the message in the browser:

您要查找的页面不存在.您可能输入错误的地址或页面可能已移动.

日志显示:

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>'

但是,如果我只是通过 bundle exec rails server 运行 rails 应用程序,我可以通过 [IP]:3000

However if I just run the rails app via bundle exec rails server I can successfully access via [IP]:3000

我怀疑该错误与 ActionController::RoutingError (No route matching [GET] "/") 有关: 但是我缺乏 Rails 知识来找出修复方法.

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.

推荐答案

您需要在 routes.rb 文件中设置根路由.

You need to setup a root route in routes.rb file.

root :to => 'index#index'

其中第一个索引是控制器名称 (IndexController),第二个索引是 IndexController 中的操作名称.

Where the first index is the controller name (IndexController) and the second index is the action name in the IndexController.

这篇关于ActionController::RoutingError(没有路由匹配 [GET] “/"):的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆