ruby – ActionController :: RoutingError(没有路由匹配[GET]“/”):

我正在玩一个使用独角兽和铁轨的教程.我对rails非常陌生,为了本教程的目的,我为该项目所做的一切都是bundle exec rails new rails-starter,没有进一步的app修改.

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

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

日志显示:

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服务器运行rails应用程序,我可以通过[IP]:3000成功访问

我怀疑错误是与ActionController :: RoutingError(没有路由匹配[GET]“/”)有关:但是我缺乏轨道知识来找出修复.

解决方法:

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

root :to => 'index#index'

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

上一篇:PHP-如何重定向用户,而不重定向Google(和其他搜寻器)?


下一篇:PHP重定向到pdf,然后导航到另一个页面?