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.
5cd805eda9338f43deaa498a22588a9f?d=identicon&s=25 Desert Penguin (desertpenguin)
on 2007-05-23 02: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
5cd805eda9338f43deaa498a22588a9f?d=identicon&s=25 Desert Penguin (desertpenguin)
on 2007-05-23 02:48
Desert Penguin 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"]
Fc49ff6d82732b73a94be2974b4dd3df?d=identicon&s=25 Gabriel Gironda (Guest)
on 2007-05-23 03:19
(Received via mailing list)
ActiveRecord::Base.configurations also already has what you seek loaded.

- Gabriel
5cd805eda9338f43deaa498a22588a9f?d=identicon&s=25 Desert Penguin (desertpenguin)
on 2007-05-23 06: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
2ced34335d6aca14ea8dec9754191dd2?d=identicon&s=25 foaud167 (Guest)
on 2007-05-23 14:22
(Received via mailing list)
On May 23, 7:02 am, Desert Penguin <rails-mailing-l...@andreas-s.net>
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.