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

查看:223
本文介绍了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:

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.

日志显示:

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 matches [GET] "/"):有关,但是我缺乏了解解决方案的知识.

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天全站免登陆