Forum: Ruby on Rails Read database.yml from a migration

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Desert P. (Guest)
on 2007-05-23 04:35
I need to know which environment and database my migration is running
for.

I can read RAILS_ENV

How do I lookup my environment in database.yml?

Thanks for any help
Desert P. (Guest)
on 2007-05-23 04:48
Desert P. wrote:
> I need to know which environment and database my migration is running
> for.
>
> I can read RAILS_ENV
>
> How do I lookup my environment in database.yml?
>
> Thanks for any help

I figured it out:

    y =
YAML::load(ERB.new((IO.read("#{RAILS_ROOT}/config/database.yml"))).result)
    db = y[RAILS_ENV]["database"]
Gabriel Gironda (Guest)
on 2007-05-23 05:19
(Received via mailing list)
ActiveRecord::Base.configurations also already has what you seek loaded.

- Gabriel
Desert P. (Guest)
on 2007-05-23 08:02
Gabriel Gironda wrote:
> ActiveRecord::Base.configurations also already has what you seek loaded.
>
> - Gabriel

Thanks for the tip - can you post an example for this?

I can't seem to find any documentation after googling....

Thanks
foaud167 (Guest)
on 2007-05-23 16:22
(Received via mailing list)
On May 23, 7:02 am, Desert P. <removed_email_address@domain.invalid>
wrote:
> Gabriel Gironda wrote:
> > ActiveRecord::Base.configurations also already has what you seek loaded.
>
> > - Gabriel
>
> Thanks for the tip - can you post an example for this?
>
> I can't seem to find any documentation after googling....

console is your best friend in such cases
just give it
ActiveRecord::Base.configurations
This topic is locked and can not be replied to.