0

I declared a module MigrationProcedures in app/concerns, which I would like to use to execute some unsupported ActiveRecord SQL statements.

Inside this module, I need to call the constant

[RAILS_ENV]['database']

but as it stands right now, rails tells me that there is an uninitialized constant RAILS_ENV in the method.

I should not that this is being used under

def self.included(base)
...
end

I tried to use AppName::RAILS_ENV but that tells me that MigrationProcedures::AppName dosen't exist. How can I call this constant?

steenslag
  • 79,051
  • 16
  • 138
  • 171
ovatsug25
  • 7,786
  • 7
  • 34
  • 48

1 Answers1

2

You can get at the Rails environment a couple of ways:

c = ::Rails.application.config
my_env = ::ENV

In the first case c.database_configuration[Rails.env]["database"] gives you what you want.

The ::SOME_MODULE syntax gets you out of your current namespace and into a new one. Without a module name, it takes you to the top of your Ruby environment.

This Stack Overflow discussion is very illuminating.

Community
  • 1
  • 1
LazyMonkey
  • 517
  • 5
  • 8