如何使用Oracle配置Ruby on Rails? [英] How to configure Ruby on Rails with Oracle?

查看:56
本文介绍了如何使用Oracle配置Ruby on Rails?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

网络上有很多页面对此进行了讨论,但是大多数页面已经过时或不准确.

There's several pages on the web that discuss this, but most are out of date or inaccurate in some way.

什么是瓢?

推荐答案

构建红宝石,宝石和导轨

按照 http://rubyonrails.org/download :

build ruby
build gem
use gem to install rails

获取Oracle Instantclient

从下载 https://www.oracle.com/technetwork/database/database-technologies/instant-client/downloads/index.html

Get Oracle Instantclient

Download from https://www.oracle.com/technetwork/database/database-technologies/instant-client/downloads/index.html

您的体系结构需要这两个软件包.

You need these two packages for your architecture.

instantclient-basic
instantclient-sdk

解压缩这些文件,并创建此链接

Unzip these files, and make this link

cd instantclient_10_2
# .dylib for mac, .so for linux
ln -s libclntsh.dylib.10.1 libclntsh.dylib

构建ruby-oci8

请注意,JRuby用户不需要ruby-oci8,但确实需要 Oracle JDBC jar ,是ojdbc6.jar还是ojdbc5.jar,具体取决于您使用的是Java 6还是Java 5.

Build ruby-oci8

Note, JRuby users don't need ruby-oci8, but do need the Oracle JDBC jar, either ojdbc6.jar or ojdbc5.jar depending on whether you have Java 6 or Java 5.

http://ruby-oci8.rubyforge.org/en/index下载.html 并运行

# DYLD for mac
export DYLD_LIBRARY_PATH=/path/to/instantclient_10_2
# LD for linux
export LD_LIBRARY_PATH=/path/to/instantclient_10_2
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

使用这一行和您的数据库连接字符串进行测试.

Test with this line and your database connection string.

ruby -r oci8 -e "OCI8.new('scott/tiger@orcl').exec('select * from user_tables') do |r| puts r.join(','); end"

安装activerecord-oracle_enhanced-adapter

请注意, 不是 activrecord-oracle-adapter ,就像许多旧页面所提到的那样.

Install activerecord-oracle_enhanced-adapter

Note, not activrecord-oracle-adapter as many older pages mention.

gem install activerecord-oracle_enhanced-adapter

做些甜蜜的事

rails railstest
cd railstest
# edit config/database.yml as below
ruby script/generate scaffold comic title:string issue:integer publisher:string
rake db:migrate
ruby script/server

在浏览器中测试

<http://localhost:3000/comics>

config/database.yml

如果您有TNS条目,请使用数据库,否则请使用 host .请注意,您有三个条目(开发,测试,生产)需要更新.

config/database.yml

Use database if you have a TNS entry, otherwise use host. Note that you have three entries (devel, test, production) to update.

development:
    adapter: oracle_enhanced
    database: orcl           # format is tns-name entry
    host:  myorclhost/orcl   # format is hostname/instance-name
    username: scott
    password: tiger

参考文献

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆