Skip to content
Browse files

fix(framework): Fixed `envs_in_console` for `rails`

Up to this commit, `envs_in_console` was creating a `config/initializers/000_console.rb` file, which
basically overloaded `Rails.application.load_console` method, with new ENVs. However, this caused
problems, since console gets loaded pretty late in initialization stack. For example, if ENVs were
used in `application/secrets.yml` (which is common practice) they wasn't loaded, since secrets is
populated before loading the console. To avoid that, a new solution was implemented -
`config/application.rb` is updated, with the ENVs (while still maintaining console context). This
ensures, that all the variables are loaded as fast as possible, and visible to as many Rails
components as they need to be.

Signed-off-by: Igor Rzegocki <>
  • Loading branch information...
ajgon committed Sep 29, 2016
1 parent c1ed974 commit f8856c82ff7c8824182ff035cb429a2d638bff2d
Showing with 12 additions and 7 deletions.
  1. +3 −0
  2. +9 −7 libraries/drivers_framework_rails.rb
@@ -186,6 +186,9 @@ ActiveRecord::Base.configurations[:production] = database_url || {
* **Default:** `false`
* If set to true, `rails console` will be invoked with all application-level
environment variables set.
* **WARNING!** This is highly unstable feature. If you experience any troubles
with deployments, and have this feature enabled, consider disabling it as a
first step in your debugging process.

### appserver

@@ -45,14 +45,16 @@ def database_yml(db)

def setup_rails_console
return unless out[:envs_in_console]
deploy_to = deploy_dir(app)
env = environment
application_rb_path = File.join(deploy_dir(app), 'current', 'config', 'application.rb')

context.template File.join(deploy_to, 'current', 'config', 'initializers', '000_console.rb') do
owner node['deployer']['user']
group www_group
source 'rails_console_overload.rb.erb'
variables environment: env
if File.exist?(application_rb_path)
env_code = "if(defined?(Rails::Console))\n " + { |key, value| "ENV['#{key}'] = #{value.inspect}" }.join("\n ") +

contents =^(?:module|class).*$)/, "#{env_code}\n\\1"), 'w') { |file| file.write(contents) }

0 comments on commit f8856c8

Please sign in to comment.
You can’t perform that action at this time.