Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## database.yml
- development:
- username: devc0_us3r
- password: s3cr3t_osit099
- database: devc0_development
- test:
- username: devc0_us3r
- password: s3cr3t_osit099
- database: devc0_test
- production:
- username: <%= ENV[ 'DB_USERNAME' ] %>
- password: <%= ENV[ 'DB_PASSWORD' ] %>
- database: <%= ENV[ 'DB_NAME' ] %>
- ## connection.rb
- config = YAML.load_file( 'database.yml' )
- # This a hash with the config vars.
- # e.g.: [ 'development' => { 'username' => '...' }, 'test' => { 'username' => '...' }, 'production' => { 'username' => '...' } ]
- # So, given you have the environment variable set to development, you want to do something like:
- connection = MySQL.connecition.new( config[ 'development' ][ 'username' ], config[ 'development' ][ 'password' ] )
- # Or if you want to simplify that procces:
- env = 'development' || 'test' || 'production'
- config = YAML.load_file( 'database.yml' )[ env ]
- connection = MySQL.connecition.new( config[ 'username' ], config[ 'password' ] )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement