zwiebl zwiebl - 4 months ago 9
Ruby Question

Translating a connection string to database.yml file in Ruby on Rails

The problem is fairly simple and straightforward. I have a database

connection string
and I want to make a corresponding
database.yml
file from it.

The connection string is as follows:

data source=qsss.gar.de\SQL2012,3000;initial catalog=City;persist security info=True;user id=user_me;password=user_me##2009;


Now, the file I created is likewise:

development:
adapter: sqlserver
host: qsss.gar.de\SQL2012,3000
port: 1433
database: City
username: user_me
password: user_me##2009


Now, the problem occurs in line 3: this
qsss.gar.de\SQL2012
is syntax-highlighted, where as the
,3000
part stays white, not highlighted but just as a normal text

Also the problem in last line:
user_me##2009
, it just recognizes
user_me
and then treats
##2009
as the comment, but this part is also a part of the password.

I noticed, if I used quotation marks, the highlighting is OK, but not sure should I use them?

My question is - how should the
database.yml
file look like for the given connection string?

Answer

use quotes " to wrap the strings.

development:
    adapter:    "sqlserver"
    host:       "qsss.gar.de\SQL2012,3000"
    port:       "1433"
    database:   "City"
    username:   "user_me"
    password:   "user_me##2009"

This way YML will only interpret these as strings and not as comments and other stuff.

Comments