Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails app fails on Heroku: (No route matches [GET] "/")

Newbie to both Rails and Heroku, and I'm trying to deploy a simple app by following the step-by-step instructions in the Rails Tutorial. The app runs fine locally and shows the default Rails starter page. But navigating to the app url in Heroku keeps giving me a 404 Page Not Found, even though it's the same app and I haven't touched the routes files or any controllers etc.

I'm on a Mac 10.6.8 with the latest Ruby (1.9.3) and Rails (4.0.0).

Things I've Tried:

Following the answer in Rails 3.1.3 on Heroku: (No route matches [GET] "/assets/rails.png") I added code to config/application.rb for lazily compiling assets in production:

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

Following the answer in Rails production static files routing error I modified production.rb to ensure static assets were being served:

config.serve_static_assets = true

But I still get the 404. What else can I try?

Heroku Log:

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'
like image 418
Yarin Avatar asked May 31 '13 17:05

Yarin


1 Answers

First of all Rails4 apps no longer serve public/index.html, or app/assets/rails.png, as those files are now handled by the rails gem itself, so you can safely ignore all talk relating to them.

Secondly, I would advise you to ignore the advice given in the question you linked to as it's not at all relevant for rails4. You will not need to procompile your assets if you're using heroku. They do it for you when you push your app to them. It's probably worth removing the public/assets folder that you created when your ran rake assets:precompile as it will just get in the way

Thirdly, remove the code you added to config/application.rb as there is no assets group in Rails 4

Fourthly, heroku used to inject a plugin for serving static assets into your app, but now you need to do that yourself by adding the following to your Gemfile:

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

Fifthly, you are using Webrick server. Heroku advise you to switch to Unicorn.

Lastly, don't worry about the default Rails landing page not being shown on Heroku. It might be a bug in their system, it happened to me, it will happen to the next guy, it would more than likely happen to Matz if he tried it too. It's no big deal. Just move on. Your app is ready for you to start developing your own landing page.

Good luck and for what it's worth, here's a very simple example Gemfile optimised for 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
like image 163
stephenmurdoch Avatar answered Oct 30 '22 12:10

stephenmurdoch