Skip to main content

database.yml rails

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
1. database host/machine
2. which database to choose ( mySQL, Oracle, Sqlite... etc)
3. Username
4. password
.
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 :

development:
adapter: mysql2
encoding: utf8
reconnect: true
database: [DB name]
pool: 5
username: [your username]
password: [your password]
host: [host name]

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:

adapter: oracle
database: comics_catalog_development
username: [your username]
password: [your password]
host: [host name]

postgres Database.yml:

development:
adapter: postgresql
encoding: unicode
database: [DB name]
pool: 5
username: [your username]
password: [your username]

IBMDB2 Database.yml:

development:
adapter: jdbc
driver: com.ibm.db2.jcc.DB2Driver
url: jdbc:db2://HOSTNAME:50000/
host: localhost
port: 50000
database: [DB name]
username: [your username]
password: [your password]

MSSQL Database.yml:

development:
adapter: sqlserver
mode: ODBC
username: [your username]
password: [your password]
database: [DB name]
dsn: my_dev_server_ds

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:

adapter: sqlite3
database: db/development.sqlite3
pool: 5
timeout: 5000

test:

adapter: sqlite3
database: db/test.sqlite3
pool: 5
timeout: 5000

production:

adapter: mysql
encoding: utf8
username: [your username]
password: [your password]
database: [DB name]
socket: /tmp/mysql.sock
host: [host machine]    
port: 3306

Comments

Popular posts from this blog

Create dynamic sitemap on ruby on rails

Sitemaps are an easy way for webmasters to inform search engines about pages on their sites that are available for crawling. In its simplest form, a Sitemap is an XML file that lists URLs for a site along with additional metadata about each URL (when it was last updated, how often it usually changes, and how important it is, relative to other URLs in the site) so that search engines can more intelligently crawl the site. It’s basically a XML file describing all URLs in your page: The following example shows a Sitemap that contains just one URL and uses all optional tags. The optional tags are in italics. <?xml version="1.0" encoding="UTF-8"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">    <url>       <loc>http://www.example.com/</loc>       <lastmod>2005-01-01</lastmod>       <changefreq>monthly</changefreq>     ...

Omniauth Linked in Ruby On Rails

def get_linkedin_user_data      omniauth = request.env["omniauth.auth"]      dat=omniauth.extra.raw_info      linked_app_key = "xxxxxxx"      linkedin_secret_key = "yyyyyyy"      client = LinkedIn::Client.new(linked_app_key,linkedin_secret_key)      client.authorize_from_access(omniauth['credentials']['token'],omniauth['credentials']['secret'])      connections=client.connections(:fields => ["id", "first-name", "last-name","picture-url"])      uid=omniauth['uid']      token=omniauth["credentials"]["token"]      secret=omniauth["credentials"]["secret"]   #linked user data     omniauth = request.env["omniauth.auth"]      data             = omniauth.info      user_name...

Install Rvm on ubuntu

sudo apt-get install libgdbm-dev libncurses5-dev automake libtool bison libffi-dev curl -L https://get.rvm.io | bash -s stable source ~/.rvm/scripts/rvm rvm install 2.0.0-p645 rvm use 2.0.0-p645 --default ruby -v rvm gemset create rails3.2.8 rvm gemset use rails3.2.8 gem install rails -v 3.2.8