2013-05-31 8 views
9

初心者はRailsとHerokuの両方に、そして私はRails Tutorialのステップバイステップの手順に従って簡単なアプリを配備しようとしています。アプリケーションはローカルで正常に動作し、デフォルトのRailsスターターページを表示します。しかし、HerokuのアプリURLに移動すると、同じアプリケーションで、経路ファイルやコントローラーなどに触れていないのに、 404ページが見つかりませんでした。RailsアプリがHerokuで失敗する:(ルートに[GET] "/"と一致しない)

私はMacを使用しています10.6 .8最新のRuby(1.9.3)とRails(4.0.0)を使ってください。私が試した

物事:Rails 3.1.3 on Heroku: (No route matches [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 static files routing errorで答えに続き、私が保証するために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' 
+0

ルートルート設定を持っていますか? – coreyward

+0

@ coreyward-いいえ、私はルートファイルに全く触れていません。アプリは本質的に 'rails new'から生成されるデフォルトです。私はなぜHerokuのデフォルトのホームページが表示されないのか不思議です。 – Yarin

答えて

17

これらのファイルは、現在レールの宝石自体によって処理されるように、すべてのRails4の最初には、no longer serve public/index.html、またはアプリ/資産/ rails.pngをアプリなので、あなたが安全にできますそれらに関連するすべての話を無視する。 あなたはそれがすべての関連rails4のためではありませんようにリンクquestionで与えられたアドバイスを無視する

第二に、私はあなたを助言します。ヒロクを使用している場合、資産をプロコンパイルする必要はありません。彼らはあなたのアプリを彼らにプッシュするときにあなたのためにそれを行います。それはおそらくあなたのRAN rake assets:precompileはそれだけの方法

になりますよう第三に、no assets group in Rails 4

が第四があるので、あなたが設定/ application.rbに追加されたコードを削除したときに作成したパブリック/資産フォルダを削除する価値があります、Herokuのは、あなたのアプリに静的な資産を提供するためのプラグインを注入するために使用されるが、今、あなたのGemfileに以下を追加することによって、do that yourselfする必要があります。

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

第五に、あなたはWEBrickにサーバーを使用しています。 Herokuはあなたにswitch to Unicornとアドバイスします。

最後に、デフォルトのRailsのランディングページがHerokuに表示されないことを心配しないでください。彼らのシステムのバグかもしれない、それは私に起こった、それは次の男に起こるだろう、それは彼がそれを試しても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 
+1

@ stephenmurdoch-この回答では、上記とそれを超えていただきありがとうございます。私はまだ私のベアリングを得ているので、このアドバイスは非常に有益です。あなたがブルックリンにいるとき私に知らせてください - 私はあなたにビールを買っています - – Yarin

+2

実際にこのトリックは、あなたが指定したリンクで私のために働いていました: 'gem 'rails_12factor'、group::production'リンク+1 :) – uday

+0

ありがとうございます:) – Doel

関連する問題