LoginSignup
2
2

More than 5 years have passed since last update.

rails_configでローカル環境のデータベース設定を上書きしたかった

Posted at

前提

設定

database.yml
<%= Settings.database.to_hash.to_yaml.gsub("---\n", "").gsub(/:(.+):/, '\1:') %>
config/settings.yml
...
database:
  development:
    adapter: sqlite3
    database: db/development.sqlite3
    pool: 5
    timeout: 5000
    reconnect: true
...
config/settings.local.yml
...
database:
  development:
    adapter: mysql2
    encoding: utf8
    reconnect: true
    database: development
    pool: 5
    username: root
    password: foobar
    host: localhost
...
Rakefile
...
RailsConfig.load_and_set_settings(
  Rails.root.join("config", "settings.yml").to_s,
  Rails.root.join("config", "settings.local.yml").to_s,
)
...

雑感

もっといい方法はないものか。特にdatabase.ymlのあたり。

2
2
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2