Posted at

Railsで、database.yml(設定ファイル)からDBのユーザー名・パスワード等を取得

More than 5 years have passed since last update.

db_config = Rails.configuration.database_configuration

db_username = db_config[Rails.env]["username"]
db_password = db_config[Rails.env]["password"]