Heroku上的Rails应用程序失败:(没有路由匹配“/”)

Rails和Heroku的新手,我正在尝试按照Rails教程中的分步说明部署一个简单的应用程序。 该应用程序在本地运行良好,并显示默认的Rails启动页面。 但导航到Heroku中的应用程序URL不断给我404找不到页面 ,即使它是相同的应用程序,我没有触及路线文件或任何控制器等。

我使用最新的Ruby(1.9.3)和Rails(4.0.0)在Mac 10.6.8上。

我试过的事情:

关于Heroku的Rails 3.1.3中的答案:(没有路由匹配[GET]“ config/application.rb assets config/application.rb rails.png”)我在config/application.rb添加了代码,用于在生产中懒惰地编译资产:

 if defined?(Bundler) # If you want your assets lazily compiled in production, use this line Bundler.require(:default, :assets, Rails.env) end 

在Rails生成静态文件路由错误的答案之后我修改了production.rb以确保提供静态资产:

 config.serve_static_assets = true 

但我仍然得到404.我还能尝试什么?

Heroku日志:

 2013-05-31T16:39:41.675219+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/"): 2013-05-31T16:39:41.675219+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 2013-05-31T16:39:41.675513+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/rack/logger.rb:21:in `call' 2013-05-31T16:39:41.675219+00:00 app[web.1]: F, [2013-05-31T16:32:49.152450 #2] FATAL -- : 2013-05-31T16:39:41.675513+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/request_id.rb:21:in `call' 2013-05-31T16:39:41.675513+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call' 2013-05-31T16:39:41.675513+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/tagged_logging.rb:67:in `block in tagged' 2013-05-31T16:39:41.676016+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 2013-05-31T16:39:41.675513+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/tagged_logging.rb:25:in `tagged' 2013-05-31T16:39:41.675513+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/static.rb:64:in `call' 2013-05-31T16:39:41.675777+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service' 2013-05-31T16:39:41.675513+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/tagged_logging.rb:67:in `tagged' 2013-05-31T16:39:41.675777+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call' 2013-05-31T16:39:41.676016+00:00 app[web.1]: F, [2013-05-31T16:32:52.415675 #2] FATAL -- : 2013-05-31T16:39:41.675513+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call' 2013-05-31T16:39:41.675777+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call' 2013-05-31T16:39:41.675777+00:00 app[web.1]: 2013-05-31T16:39:41.675777+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/engine.rb:511:in `call' 2013-05-31T16:39:41.675777+00:00 app[web.1]: 2013-05-31T16:39:41.676016+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/tagged_logging.rb:67:in `block in tagged' 2013-05-31T16:39:41.675777+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/application.rb:96:in `call' 2013-05-31T16:39:41.675777+00:00 app[web.1]: vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' 2013-05-31T16:39:41.675777+00:00 app[web.1]: vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' 2013-05-31T16:39:41.676016+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 2013-05-31T16:39:41.675513+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/cache/strategy/local_cache.rb:83:in `call' 2013-05-31T16:39:41.676016+00:00 app[web.1]: I, [2013-05-31T16:32:52.414612 #2] INFO -- : Started GET "/" for 67.244.94.162 at 2013-05-31 16:32:52 +0000 2013-05-31T16:39:41.676016+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/rack/logger.rb:21:in `block in call' 2013-05-31T16:39:41.676016+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/rack/logger.rb:38:in `call_app' 2013-05-31T16:39:41.676253+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/static.rb:64:in `call' 2013-05-31T16:39:41.676016+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/"): 2013-05-31T16:39:41.676016+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/tagged_logging.rb:25:in `tagged' 2013-05-31T16:39:41.676253+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call' 2013-05-31T16:39:41.676253+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/request_id.rb:21:in `call' 2013-05-31T16:39:41.675777+00:00 app[web.1]: vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' 2013-05-31T16:39:41.676016+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/tagged_logging.rb:67:in `tagged' 2013-05-31T16:39:41.676253+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/application.rb:96:in `call' 2013-05-31T16:39:41.676490+00:00 app[web.1]: 2013-05-31T16:39:41.676253+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/cache/strategy/local_cache.rb:83:in `call' 2013-05-31T16:39:41.676490+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service' 2013-05-31T16:39:41.676490+00:00 app[web.1]: 2013-05-31T16:39:41.676253+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call' 2013-05-31T16:39:41.676253+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call' 2013-05-31T16:39:41.676490+00:00 app[web.1]: vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' 2013-05-31T16:39:41.676253+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call' 2013-05-31T16:39:41.676253+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/engine.rb:511:in `call' 2013-05-31T16:39:41.676490+00:00 app[web.1]: vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' 2013-05-31T16:39:41.676490+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 2013-05-31T16:39:41.676253+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/rack/logger.rb:21:in `call' 2013-05-31T16:39:41.676490+00:00 app[web.1]: I, [2013-05-31T16:38:42.543864 #2] INFO -- : Started GET "/" for 67.244.94.162 at 2013-05-31 16:38:42 +0000 2013-05-31T16:39:41.676725+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/rack/logger.rb:21:in `call' 2013-05-31T16:39:41.676725+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call' 2013-05-31T16:39:41.676725+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/tagged_logging.rb:67:in `tagged' 2013-05-31T16:39:41.676725+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/rack/logger.rb:38:in `call_app' 2013-05-31T16:39:41.676490+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/"): 2013-05-31T16:39:41.676725+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 2013-05-31T16:39:41.676725+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/tagged_logging.rb:67:in `block in tagged' 2013-05-31T16:39:41.676725+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/tagged_logging.rb:25:in `tagged' 2013-05-31T16:39:41.676725+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call' 2013-05-31T16:39:41.676490+00:00 app[web.1]: vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' 2013-05-31T16:39:41.676490+00:00 app[web.1]: F, [2013-05-31T16:38:42.544833 #2] FATAL -- : 2013-05-31T16:39:41.677196+00:00 app[web.1]: 2013-05-31T16:39:41.677196+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call' 2013-05-31T16:39:41.676961+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/cache/strategy/local_cache.rb:83:in `call' 2013-05-31T16:39:41.676961+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call' 2013-05-31T16:39:41.676961+00:00 app[web.1]: vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' 2013-05-31T16:39:41.676961+00:00 app[web.1]: vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' 2013-05-31T16:39:41.677196+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/tagged_logging.rb:67:in `block in tagged' 2013-05-31T16:39:41.677432+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/request_id.rb:21:in `call' 2013-05-31T16:39:41.677196+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call' 2013-05-31T16:39:41.677665+00:00 app[web.1]: vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:94:in `run' 2013-05-31T16:39:41.676961+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/static.rb:64:in `call' 2013-05-31T16:39:41.677196+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/rack/logger.rb:38:in `call_app' 2013-05-31T16:39:41.677432+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call' 2013-05-31T16:39:41.676961+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/engine.rb:511:in `call' 2013-05-31T16:39:41.676961+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call' 2013-05-31T16:39:41.677196+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/rack/logger.rb:21:in `block in call' 2013-05-31T16:39:41.677432+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/rack/logger.rb:21:in `call' 2013-05-31T16:39:41.677432+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/engine.rb:511:in `call' 2013-05-31T16:39:41.677665+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call' 2013-05-31T16:39:41.676725+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/rack/logger.rb:21:in `block in call' 2013-05-31T16:39:41.676725+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/request_id.rb:21:in `call' 2013-05-31T16:39:41.676961+00:00 app[web.1]: vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' 2013-05-31T16:39:41.677196+00:00 app[web.1]: 2013-05-31T16:39:41.677196+00:00 app[web.1]: I, [2013-05-31T16:39:41.674148 #2] INFO -- : Started GET "/" for 67.244.94.162 at 2013-05-31 16:39:41 +0000 2013-05-31T16:39:41.676969+00:00 heroku[router]: at=info method=GET path=/ host=floating-refuge-5703.herokuapp.com fwd="67.244.94.162" dyno=web.1 connect=0ms service=5ms status=404 bytes=1351 2013-05-31T16:39:41.676961+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/application.rb:96:in `call' 2013-05-31T16:39:41.676961+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service' 2013-05-31T16:39:41.677196+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/"): 2013-05-31T16:39:41.677432+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call' 2013-05-31T16:39:41.677665+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call' 2013-05-31T16:39:41.677432+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/tagged_logging.rb:67:in `tagged' 2013-05-31T16:39:41.677665+00:00 app[web.1]: 2013-05-31T16:39:41.677432+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/actionpack-4.0.0.rc1/lib/action_dispatch/middleware/static.rb:64:in `call' 2013-05-31T16:39:41.677665+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service' 2013-05-31T16:39:41.677432+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/cache/strategy/local_cache.rb:83:in `call' 2013-05-31T16:39:41.677665+00:00 app[web.1]: vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/httpserver.rb:138:in `service' 2013-05-31T16:39:41.677665+00:00 app[web.1]: 2013-05-31T16:39:41.677196+00:00 app[web.1]: F, [2013-05-31T16:39:41.675079 #2] FATAL -- : 2013-05-31T16:39:41.677432+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/activesupport-4.0.0.rc1/lib/active_support/tagged_logging.rb:25:in `tagged' 2013-05-31T16:39:41.677432+00:00 app[web.1]: vendor/bundle/ruby/1.9.1/gems/railties-4.0.0.rc1/lib/rails/application.rb:96:in `call' 2013-05-31T16:39:41.677665+00:00 app[web.1]: vendor/ruby-1.9.3/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread' 

首先,Rails4应用程序不再提供public / index.html或app / assets / rails.png ,因为这些文件现在由rails gem本身处理,因此您可以放心地忽略与它们相关的所有谈话。

其次,我建议你忽略你所链接的问题中给出的建议,因为它与rails4完全无关。 如果您使用的是heroku,则无需预编译您的资产。 当您将应用推送给他们时,他们会为您做到这一点。 你可能有必要删除你运行rake assets:precompile时创建的public / assets文件夹rake assets:precompile因为它会妨碍你

第三,删除你添加到config / application.rb的代码,因为Rails 4中没有资产组

第四,heroku用于注入一个插件,用于将静态资产提供到您的应用程序中,但现在您需要通过在Gemfile中添加以下内容来自行完成:

 gem 'rails_log_stdout', github: 'heroku/rails_log_stdout' gem 'rails3_serve_static_assets', github: 'heroku/rails3_serve_static_assets' 

第五,您正在使用Webrick服务器。 Heroku建议你切换到Unicorn 。

最后,不要担心Heroku上没有显示默认的Rails登陆页面。 它可能是他们系统中的一个错误,它发生在我身上,它会发生在下一个人身上,如果他也尝试过它,很可能会发生在Matz身上。 这没什么大不了的。 继续前进。 您的应用已准备好开始开发自己的目标网页了。

祝你好运,这是一个非常简单的Gemfile示例,该示例针对heroku进行了优化:

 source 'https://rubygems.org' # you are using Ruby 1.9.3, better to 2.0.0 upgrade for more speed ruby '2.0.0' gem 'rails', '4.0.0.rc1' gem 'sass-rails', '~> 4.0.0.rc1' gem 'uglifier', '>= 1.3.0' gem 'coffee-rails', '~> 4.0.0' gem 'jquery-rails' gem 'turbolinks' gem 'jbuilder', '~> 1.0.1' # The asset_sync gem is WELL worth using # but you should read more about it before deciding # https://github.com/rumblelabs/asset_sync # gem 'asset_sync' # only want sqlite in dev and test envs group :development, :test do gem 'sqlite3' end group :production do gem 'pg' # dont want sqlite in production gem 'unicorn' # make sure you follow installation instructions for this gem gem 'rails_log_stdout', github: 'heroku/rails_log_stdout' gem 'rails3_serve_static_assets', github: 'heroku/rails3_serve_static_assets' end group :doc do gem 'sdoc', require: false end