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

Gem::LoadError (Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).?

Gem::LoadError (Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).) In rails?


1)change the gemfile in mysql version
 gem 'mysql2'

2)Change to mysql2 version
 gem 'mysql2','0.3.20'

Get user accessing ip address in rails?

Get user accessing ip address rails?

request.ip ->returns the ip, whether is is a local proxy ip (localhost address) or not.
*request.remote_ip -> is smarter and gets the ip address of the client outside of local proxies.
3)If you are using apache in front of a mongrel, then remote_ip will return the source address of the request, which in this case will be local host because the Apache web server is making the request, so instead put this in your controller:

@remote_ip = request.env["HTTP_X_FORWARDED_FOR"]

PayUMoney Integration in Ruby on Rails

PayUMoney Integration in Ruby on Rails


Generating Cheksum in Payu
   Hash or Checksum
= sha512(key|txnid|amount|productinfo|firstname|email|u
df1|udf2|udf3|udf4|udf5||||||salt)



Controller Code Will be
def payumoney
  @key = "gtKFFx"
  @salt =  "eCwWELxi"
  val = "#{key|txnid|amount|productinfo|firstname|email|u
df1|udf2|udf3|udf4|udf5||||||#{@salt}"
 @checksum = Digest::SHA512.hexdigest("#{val}")
end

<form action="https://test.payu.in/_payment" method='post' id='sub'  >
    <input type="hidden" name="key" value="<%=@key%>">
    <input type="hidden" name="hash" value="<%=@checksum%>">
    <input type="hidden" name="txnid" value="TXN1234">
    <input type="hidden" name="amount" value="200">
    <input type="hidden" name="firstname" value=&quo…