Heroku website crashes with Rails 3.2.9 and route constraint

heroku, ruby, ruby-on-rails, ruby-on-rails-3, ruby-on-rails-3.2

Solution

Can you try out the following versions in your Gemfile:

# Gemfile
gem 'rails', '3.2.9'
gem 'high_voltage', '~> 1.2.1'
gem 'thin'

# ...

The `1.2.1` release of High Voltage has the root route constraints baked into it. This will allow you to remove the routes completely from your `config/routes.rb` file.

Just set up an initializer for High Voltage:

# config/initializers/high_voltage.rb
HighVoltage.route_drawer = HighVoltage::RouteDrawers::Root

I deployed the above to a Cedar app on Heroku and it ran as expected.

Problem

My website, hosted in Heroku, has been working fine with Rails 3.2.8. I'm using a route constraint class with the HighVoltage gem for static (mostly) webpages: routes.rb: ``` get "/*id" => "high_voltage/pages#show", constraints: Constraints::StaticPage.new ``` I have a file in `/lib/constraints/static_page.rb`: ``` module Constraints class StaticPage def matches?(request) File.exist? file_path(request.path) end private def file_path(view) static_page_views_dir.to_s.concat("#{view}.html.erb") end def static_page_views_dir Rails.root.join('app', 'views', 'pages') end end end ``` Problem is, I just updated to Rails 3.2.9 and did a `git push heroku` and my app crashed :( ``` my-host:my-site scott$ heroku ps === web: `bundle exec rails server -p $PORT` web.1: crashed 2012/11/14 12:14:41 (~ 2s ago) ``` Apparently, Ruby/Heroku can't find my `Constraints::StaticPage` class. I have it `require`d at the top of my `routes.rb`: ``` require 'constraints/static_page' ``` Did something change in Rails 3.2.9 so that no longer works with Heroku? Locally everything works fine, just not in Heroku. If I take out that constraint in my route, everything works perfect (aside from not having those constraints). Here's my `heroku logs` output: ``` 2012-11-14T20:14:36+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 2012-11-14T20:14:36+00:00 app[web.1]: DEPRECATION WARNING: You have Rails 2.3-style plugins in vendor/plugins! Support for these plugins will be removed in Rails 4.0. Move them out and bundle them in your Gemfile, or fold them in to your app as lib/myplugin/* and config/initializers/myplugin.rb. See the release notes for more on this: http://weblog.rubyonrails.org/2012/1/4/rails-3-2-0-rc2-has-been-released. (called from <top (required)> at /app/config/environment.rb:5) 2012-11-14T20:14:38+00:00 app[web.1]: => Booting WEBrick 2012-11-14T20:14:38+00:00 app[web.1]: => Rails 3.2.9 application starting in production on http://0.0.0.0:18361 2012-11-14T20:14:38+00:00 app[web.1]: => Call with -d to detach 2012-11-14T20:14:38+00:00 app[web.1]: => Ctrl-C to shutdown server 2012-11-14T20:14:38+00:00 app[web.1]: Exiting 2012-11-14T20:14:38+00:00 app[web.1]: /app/config/routes.rb:50:in `block in <top (required)>': uninitialized constant ActionDispatch::Routing::Mapper::Constraints::StaticPage (NameError) 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:282:in `instance_exec' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:282:in `eval_block' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/actionpack-3.2.9/lib/action_dispatch/routing/route_set.rb:260:in `draw' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/config/routes.rb:3:in `<top (required)>' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `block in load_paths' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `each' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:34:in `execute_hook' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:43:in `block in run_load_hooks' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:42:in `each' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:42:in `run_load_hooks' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application/finisher.rb:52:in `block in <module:Finisher>' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:40:in `load_paths' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/devise-2.1.2/lib/devise/rails.rb:14:in `block in <class:Engine>' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application/routes_reloader.rb:16:in `reload!' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application.rb:108:in `reload_routes!' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/activesupport-3.2.9/lib/active_support/lazy_load_hooks.rb:34:in `call' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:55:in `block in run_initializers' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `run_initializers' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/config/environment.rb:5:in `<top (required)>' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/railtie/configurable.rb:30:in `method_missing' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/config.ru:4:in `block in <main>' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/application.rb:136:in `initialize!' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:54:in `each' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `run' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/config.ru:1:in `new' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/initializable.rb:30:in `instance_exec' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:50:in `tap' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:50:in `<top (required)>' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/config.ru:1:in `<main>' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:200:in `app' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands/server.rb:46:in `app' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/rack-1.4.1/lib/rack/server.rb:252:in `start' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands/server.rb:70:in `start' 2012-11-14T20:14:38+00:00 app[web.1]: from /app/vendor/bundle/ruby/1.9.1/gems/railties-3.2.9/lib/rails/commands.rb:55:in `block in <top (required)>' 2012-11-14T20:14:38+00:00 app[web.1]: from script/rails:6:in `require' 2012-11-14T20:14:38+00:00 app[web.1]: from script/rails:6:in `<main>' 2012-11-14T20:14:40+00:00 heroku[web.1]: Process exited with status 1 2012-11-14T20:14:40+00:00 heroku[web.1]: State changed from starting to crashed ```

Original source