Question

I have deployed my application to Heroku and forked the environment to create a 'staging' environment. I copied my paroduction.rb file to create a staging.rb, but when I change the RAILS_ENV and RACK_ENV variables from production to staging no assets are returned and the logs show the following type errors:

2014-05-05T07:42:33.614170+00:00 app[web.1]: F, [2014-05-05T07:42:33.610206 #2] FATAL -- :
2014-05-05T07:42:33.614172+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/assets/application-835271b3bd7cf8b176e8b30d9ca395fd.js"):
2014-05-05T07:42:33.614173+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
2014-05-05T07:42:33.614174+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
2014-05-05T07:42:33.614176+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/rack/logger.rb:38:in `call_app'
2014-05-05T07:42:33.614177+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/rack/logger.rb:20:in `block in call'
2014-05-05T07:42:33.614178+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/tagged_logging.rb:68:in `block in tagged'
2014-05-05T07:42:33.614200+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/tagged_logging.rb:26:in `tagged'
2014-05-05T07:42:33.614202+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/tagged_logging.rb:68:in `tagged'
2014-05-05T07:42:33.614203+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/rack/logger.rb:20:in `call'
2014-05-05T07:42:33.614204+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/actionpack-4.0.4/lib/action_dispatch/middleware/request_id.rb:21:in `call'
2014-05-05T07:42:33.614206+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
2014-05-05T07:42:33.614207+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2014-05-05T07:42:33.614218+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.4/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
2014-05-05T07:42:33.614219+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
2014-05-05T07:42:33.614221+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/engine.rb:511:in `call'
2014-05-05T07:42:33.614222+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/railties-4.0.4/lib/rails/application.rb:97:in `call'
2014-05-05T07:42:33.614224+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
2014-05-05T07:42:33.614225+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
2014-05-05T07:42:33.614226+00:00 app[web.1]:   vendor/bundle/ruby/2.0.0/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
2014-05-05T07:42:33.614228+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
2014-05-05T07:42:33.614229+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
2014-05-05T07:42:33.614231+00:00 app[web.1]:   vendor/ruby-2.0.0/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

I have found other posts on Stackoverflow e.g.: ActionController::RoutingError (No route matches [GET] "/assets/images/control_top.png"): in rails 3.2.8

and indeed changing config.serve_static_assets = false to true solves the problem, but I am reluctant to do this in just my staging environment and I understand that this will affect performance within the production environment.

What I really do not understand is why this error is occurring when the only difference as far as I can tell is that the environment variable names are changed. So to my question:

What does changing these environment variables actually change about the application? Why does it have this effect in my application?

As a bonus if there is a better way to solve the underlying problem I have described to have staging mirroring the production config I would appreciate the guidance.

Was it helpful?

Solution

Further investigation has established that the setting of environment variables has the following effect within deployment:

  1. The environment-specific configuration files (such as config/environments/production.rb)
  2. installation of gems as defined within the Gemfile group (e.g. group :production)

In this case heroku requires the gem 'rails_12factor' to enable static assets to be served. Therefore in addition to the group :production this gem is required for :staging.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top