How to customize config/database.yml

Short form: What’s the best way to customize my environment so “rails
new …” uses a custom template rather than the default?

Long form: Every time I create a new Rails project, the first thing I do
is edit config/database.yml so the lines that previously read:

development:
adapter: mysql
encoding: utf8
reconnect: false
database: myapp_development
pool: 5
username: root
password:
socket: /tmp/mysql.sock

instead read:

development:
adapter: mysql
encoding: utf8
reconnect: false
database: myapp_development
pool: 5
username: <%= ENV[‘MYSQL_USERID’] || “root” %>
password: <%= ENV[‘MYSQL_PASSWORD’] || “” %>
socket: <%= ENV[‘MYSQL_SOCKET’] || “/tmp/mysql.sock” %>

… that is, it picks up the values for username, password and socket
from environment variables I’ve set.

I could edit $RAILS/generators/…mysql.yml directly, but there are
two problems: first, it’s a bad idea to modify core files, and second,
it pre-expands the .yml code so my username and password are exposed in
the resulting file. Not what I want…

Another approach would be to write a rake task to post-facto modify the
file, but that seems a bit clunky.

WWDHD? (What would David Heinemeier do?)

  • ff

On Aug 12, 1:55 pm, Fearless F. [email protected] wrote:

Short form: What’s the best way to customize my environment so “rails
new …” uses a custom template rather than the default?

Sounds like you want rails’ app templates ( there’s a screencast at
http://railscasts.com/episodes/148-app-templates-in-rails-2-3 )

Fred

Frederick C. wrote:

On Aug 12, 1:55�pm, Fearless F. [email protected] wrote:

Short form: What’s the best way to customize my environment so “rails
new …” uses a custom template rather than the default?

Sounds like you want rails’ app templates ( there’s a screencast at
http://railscasts.com/episodes/148-app-templates-in-rails-2-3 )

Fred

perfect!! templates rock. ryanb rocks. you rock too – thanks for the
pointer.

  • ff

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs