Using a custom database in Rails in a rake task

Recently, I needed to run a one-time task from my local environment against a remote environment in Rails. In doing so, I needed to customize a connection for some obscure non-production calls (things like calling system commands, and direct DB queries). In any case, the code looked like:

In an initializer or rake task:

CONFIG = YAML::load('config/custom_database.yml'))

In the /config directory


``` default: &default adapter: postgis encoding: utf8

development: <<: *default database: database username: username password: password host: host port: 5482 ```

About Afomi

Afomi is the digital sandbox of Ryan Wold, who is always evolving this to better share inspirations and aspirations.

About Ryan

Ryan is a systems-thinking Product Developer and Designer who practices agile, test-driven, and lean continuous software delivery, while solving problems with people.