Rails connection to Oracle Database

Source: Internet
Author: User

 

Rails connection to Oracle Database

Preparations:

1) install ActiveRecord Oracle adapter

 

 

Sudo gem install activerecord-oracle-adapter -- source http://gems.rubyonrails. org2) install Oracle Client

Http://www.oracle.com/technology/tech/oci/instantclient/index.html

 

An error may occur during the installation process. Generally, a prompt is displayed, and the following steps may be performed:

2.1) sudo ln-s libclntsh. dylib.10.1 libclntsh. dylib

2.2) set the environment variable. You can add it in. profile for Mac.

 

 

Export DYLD_LIBRARY_PATH = "/usr/local/oracle/instantclient_10_2"

3) install the ruby oracle driver and modify the driver according to your system environment.

 

 

Sudo env DYLD_LIBRARY_PATH = $ DYLD_LIBRARY_PATH ARCHFLAGS = "-arch x86_64" gem install ruby-oci8

 

 

For installation instructions, refer to the following article:

Http://blog.rayapps.com/2009/09/06/how-to-setup-ruby-and-oracle-instant-client-on-snow-leopard/

 

The project requires the Rails application to connect to mysql and Oracle DB at the same time, so you only need to modify the configuration in the config/database. yml file:

The following configuration generally uses the 'development' configuration by default and connects to the sqlite3 database.

 

 

Development: adapter: sqlite3 database: db/development. sqlite3 pool: 5 timeout: 5000 iisp: adapter: oracle encoding: utf8 database: 192.168.68.22/iisp. xjgz username: iisp916 password: iisp916

 

In iisp/database, the IP address is followed by the database Sid, not the database Name

 

Add the following code to the model to connect to oracle:

 

 

Establish_connection 'iisp 'self. table_name = 't_ capacity 'self. sequence_name ='s _ capacity' # primary key generation

Set the code for Rails to connect to Oracle:

Add the following code to config/environment. rb:

 

 

ENV ['nls _ lang'] = 'American _ AMERICA. utf8'

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.