Last Updated: February 25, 2016
·
1.476K
· aderyabin

Drying Rails database configuration file

My database.yml file for development environment using Postgresql.

defaults: &defaults
  adapter: postgresql
  encoding: utf8
  collation: en_US.utf8
  ctype: en_US.utf8
  template: template0

<% %w(development test production).each do |environment| %>
<%= environment %>:
  <<: *defaults
  database: <%= "#{Rails.application.class.parent_name.downcase}_#{environment}" %>
<% end %>

2 Responses
Add your response

extremely ruby!

over 1 year ago ·

That's far too crazy, it's not readable! And setting a database name by evaluating some ruby code might be ok for development but a bit scary for production :)

Nevertheless, configuration files must be readable!

over 1 year ago ·