How to connect to oracle database in ROR application ?
The Ruby on Rails default use MySql database to store object datas. It also support other large DBMS like
MS Sql server,oracle. But if you want to use database systems other than MySql, you should install the relevant
databse driver and library. My compute has an oracle database installed, so I must install oracle driver and libs.
First, I decided to use Ruby/OCI8. I downloaded the software in rubyforge.org.
Then I install it,it will copy OCI8.rb,oci8lib.so to ruby lib folder. After this, you can check whether it's ok by running:ruby -r oci8 -e "OCI8.new('scott', 'tiger', nil).exec('select * from emp') do |r| puts r.join(','); end" .
Now it can work, you have to edit the config file: config/database.yml, my setup is:
adapter: oci
database:
username: test
password: test
host: test
The parameter of host must be your local service name, and the blank before your password must exists. Ok, you can now create a table in database, and create a model class using the table and a controller. In the controller class, only add a line "scaffold :recipe". Ok, the setup completed, startup the server, type "http://localhost:3000/XXX" in browser,where XXX is your controller name. You can now operate your table. Great! Is it simple ?