Follow this link to install Ruby for your system.
Download the source from the link above and extract it.
Change dir to where you extracted it.
Run configure script to specify where you want to install it. This script is used as follows:
./configure --prefix=/place/where/you/want/to/install
Let’s call the path you gave to prefix $RUBY_HOME (This is not an environment variable, just a reference in this text for the sake of explanation)
Run:
make
make test
make install
At this point, Ruby executable will be under the directory bin under the directory you specified for the configure script.
Use the following command to make Ruby executable visible:
setenv PATH RUBY_HOME/bin:$PATH
After installing Ruby, you should install Ruby's package manager, RubyGems. For that, download the corresponding file fromhere; extract it and run
ruby setup.rb
Now you can use gem package manager to install the additional packages that are needed, first of which is the Rails framework. Run
gem install rails --include-dependencies
to get Rails framework.
First you need to install is the Oracle Instant Client:
Follow this link.
Select your system and download most current versions of these two files: Instant Client Package - Basic (~40MB) and Instant Client Package - SDK (~1MB).
Use Linux x86-64 option
Unzip the packages to the same directory (simply do not specify a target directory and they will be unzipped under the current directory under a directory called instantclient_11_1)
If instantclient_11_1/libclntsh.so is not found, make a symbolic link to link the library.
cd instantclient_11_1
ln -s libclntsh.so.11.1 libclntsh.so
Set your OS's library search path to point to the installed location (for example~/project/instantclient_11_1 ). For Windows, this variable is the PATH variable, and for Unix it is the LD_LIBRARY_PATH variable.
Download and install ruby oci 8 from here
Download the source version from the link above (tar.gz format, last version is 1.0.6), extract it and install it as follows:
gzip -dc ruby-oci8-VERSION.tar.gz | tar xvf -
cd ruby-oci8-VERSION
make
make install
Run the following command
gem install activerecord-oracle-adapter --source http://gems.rubyonrails.org
This should install Oracle’s ActiveRecord adapter.
Login to sqlplus
Create a state codes table and populate it:
CREATE TABLE CODES
(ID NUMBER(38) NOT NULL,
CODE VARCHAR(50),
STATE VARCHAR(50),
CONSTRAINT PKID PRIMARY KEY (ID));
INSERT INTO CODES VALUES (1, 'MD', 'MARYLAND');
INSERT INTO CODES VALUES (2, 'NY', 'NEW YORK');
INSERT INTO CODES VALUES (3, 'NJ', 'NEW JERSEY');
Note that a field called ID is required for Ruby as a means for accessing the records.
Exit sqlplus and create the workspace for your project:
rails codes –d oracle
cd codes
Edit the codes/conf/database.yml to look like this:
development:
adapter: oracle
database: ginger.umd.edu/dbclass2
username: YOUR ORACLE USERNAME
password: YOUR ORACLE PASSWORD
Replace the file's text with the text above. Do not forget to change the database parameter in addition to your username and password.
There are a number of approaches to creating a Web application in Rails, but the simplest by far is to use scaffold, a command line feature in Rails, which will build the entire application in a single command.
ruby script/generate scaffold code code:string state:string
Now we are ready to start the web server.
ruby script/server
Goto URL: http://localhost:3000/codes/ in your browser.
Play with the website. Add and remove tuples. You can also check and see if they really modify the database.
Now, let's write/execute an actual SQL query of our own.
Open the codes_controller.rb file in ~/codes/app/controllers/ directory.
Replace the line in index function, which says
@codes = Code.all
with
@codes = Code.find_by_sql("SELECT * FROM codes WHERE country LIKE 'N%'")
Now we should be getting states starting with 'N' only.