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'