12

Rails 和 Heroku 的新手,我正在尝试按照Rails 教程中的分步说明部署一个简单的应用程序。该应用程序在本地运行良好,并显示了默认的 Rails 起始页。但是导航到 Heroku 中的应用程序 url 总是给我一个404 Page Not Found,即使它是同一个应用程序并且我没有触及路由文件或任何控制器等。

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

我尝试过的事情:

按照Heroku 上 Rails 3.1.3 中的答案:(没有路线匹配 [GET] "/assets/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'
4

1 回答 1

19

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

其次,我建议您忽略您链接到的问题中给出的建议,因为它与 rails4 完全无关。如果您使用 heroku,则不需要编译您的资产。当您将应用程序推送给他们时,他们会为您执行此操作。可能值得删除您在运行时创建的 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

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

祝你好运,值得一提的是,这里有一个为 heroku 优化的非常简单的 Gemfile 示例:

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
于 2013-05-31T21:11:27.073 回答