connect to Oracle in Ruby on Rails.

 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 ?
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值