database.yml rails
Database.yml is one of the most important files in rails project, database.yml rails is actualy a configuration file.
What is Contains?
Database.yml is configuration file which tells rails about database, database information such as
|
|
---|---|
host | URL of the Host Machine where database is installed. If over a network then IP/Web address and if local then 127.0.0.1 |
database | The name of database to be selected. Rails way is mydb_development |
username | The username of the database chosen |
password | password for the user account with given username to the database |
adaptor | Type of database being used for the Rails application (can be any MySQL/Oracle/Sqlite... etc) |
pooling | Related to maximum number of connections to be made with database |
There are such multiple configurations here in this file. You need to write appropriate values in this configuration based on the Database you are using, and host/machine of the DB. If you want to use MySQL Database.yml :
Now If you are a java programmer, you might land up with a question in your mind that what about the drivers/connectors required. In java we need JAR files depending upon the database we are using.Rails will automatically detect the drivers based on the adapter parameter in the yml file and connect appropriately. You just need to provide appropriate Jem which is equivalent to a Jar file. With the above yml file your project is good to proceed. Similarly you need to change some configurations to connect to some other database, such as Oracle. Oracle Database.yml:
postgres Database.yml:
IBMDB2 Database.yml:
MSSQL Database.yml:
Rails has capability to connect to majority of the databases present today. You can also create database.yml with various environments such as you need some different database for development,testing,production as : development:
test:
production:
;
Subscribe to Ruby in Rails
Get the latest posts delivered right to your inbox