On Feb 21, 2008, at 12:49 AM, Jean N. wrote:
Create
but I’m still confused how the block is begun/ended. It’s easy
enough to
see with do/end or curly braces…but this notation is just foreign to
me. (Summarized question, how does the <<: *login know to insert only
the username: password: From the read file and not all the other
stuff.
Sorry I realise I’m moving off Rails into more Ruby questions now…
Your help is very appreciated.
The issue is that &login is not a “block”, this is YAML not Ruby. You
read up on it go to the spec linked from YAML Ain’t Markup Language (YAML™) Version 1.1
the YAML home page.
As for whether to keep database.yml in the repository, I vote yes –
even if you put a different file in place on production during
deployment. Here’s how I’ve done it:
vvv Copy the following two YAML maps to a file called config/
mydatabase.yml
login: &login
username: default_user
password: default_password
connection: &connection
host: 127.0.0.1
port: 3306
encoding: utf8
^^^ Copy the previous two YAML maps to a file called config/
mydatabase.yml
<%= file = File.join(RAILS_ROOT, “config”, “mydatabase.yml”)
IO.read(file) if File.exist?(file) %>
development:
adapter: mysql
database: projectname_development
<<: *login
<<: *connection
Those lines are taken directly from a database.yml (changing only
username, password, and database to protect the guilty). This file is
in the repository. I split the login credentials from the connection
parameters to deal with the port versus Unix socket of MySQL and on a
recent project, even split out the adapter so cope with PostgreSQL
versus MySQL.
The mydatabase.yml file contains just those YAML maps that need to be
changed from the default. Typically I only have the connection
specified. The mydatabase.yml file is never in the repository. I
keep mydatabase-production.yml locally as a backup to the one in
production. I’ve also seen a similar arrangement that reads the
separate YAML file a second time at the end of the database.yml, but I
don’t recall the reason that was done (although I remember that the
explanation made sense for what was being done).
-Rob
Rob B. http://agileconsultingllc.com
[email protected]