Rails::Generators::Actions#environment is outdated and fails for v3.1rc4 #2110

Closed
andreif opened this Issue Jul 16, 2011 · 2 comments

2 participants

@andreif

The whole source of the method:

# File railties/lib/rails/generators/actions.rb, line 93
def environment(data=nil, options={}, &block)
  sentinel = /class [a-z_:]+ < Rails::Application/
  data = block.call if !data && block_given?

  in_root do
    if options[:env].nil?
      inject_into_file 'config/application.rb', "\n  #{data}", :after => sentinel, :verbose => false
    else
      Array.wrap(options[:env]).each do|env|
        append_file "config/environments/#{env}.rb", "\n#{data}", :verbose => false
      end
    end
  end
end

Now if I use this method environment('config.blah = "blah"', env: 'development'), then I get

# config/environments/development.rb
MyApp::Application.configure do
  # Settings specified here will take precedence over those in config/application.rb
  config.cache_classes = false
  # ...
end

config.blah = "blah"

So the line append_file "config/environments/#{env}.rb", "\n#{data}", :verbose => false should be replaced by inject_into_file(...)

@spastorino
Ruby on Rails member

Are you able to provide a test case + patch?. Thanks.

@andreif

I am not sure that I will make it in a correct way. I use

inject_into_file "config/environments/#{env}.rb", "\n  config.#{expr}", :after => /\w+::Application.configure do/, :verbose => false

but I need some guidelines for making a patch and a test case for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment