Friday, November 14, 2008

Connecting rails application with oracle 8i

1. Install Oracle Instant ClientDownloaded the Instant Client packages for free from Oracle.
All I needed are these two from Version 10.2:
->Instant Client Package - Basicinstantclient-basic-linux-x86-64-10.2.0.3-20070103.zip (36 MB)
->Instant Client Package - SDKinstantclient-sdk-linux-x86-64-10.2.0.3-20070103.zip (0.6 MB)I had downloaded the files into /opt/oracle.
# mkdir /opt/oracle
# cd /opt/oracle
# unzip /proj/downloads/instantclient-basic-linux-x86-64-10.2.0.3-20070103.zip
# unzip /proj/downloads/instantclient-sdk-linux-x86-64-10.2.0.3-20070103.zip
# cd instantclient_10_2
Then create the following symbolic link
# ln -s libclntsh.so.10.1 libclntsh.so
Edit /etc/bashrc to include the directory in your LD_LIBRARY_PATH environment variable by adding these linesLD_LIBRARY_PATH=/opt/oracle/instantclient_10_2:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH

2. Install ruby-oci8Download version 1 of the interface from rubyforge:
# wget http://rubyforge.org/frs/download.php/16630/ruby-oci8-1.0.0-rc1.tar.gz
Unpack, make and install the package# tar -zxvf ruby-oci8-1.0.0-rc1.tar.gz
# cd ruby-oci8-1.0.0-rc1
# make
# make install
The make calls ruby setup.rb to configure and then compile the code.
It should all go smoothly provided the Oracle libraries are in place and it knows where to find them.

3. configuring database.yml file of rails application.

I connected to dev database in the host one.cisco.com
development:
adapter: oci
host: one.cisco.com/dev
username:
password:

Note : Note : In /usr/local/lib/ruby/gems/1.8/gems/activerecord-2.1.2/lib/active-record/connection-adapters , change oracle_adapter.rb to oci_adapter.rb
#cp oracle_adapter.rb oci_adapter.rb

Tuesday, September 23, 2008

Get started with 'Regular Expressions'

Ruby supports majority of standard regular expression syntax.
Regular expression is pattern that either does or does not match any given string.
A regular expression in ruby is placed between a pair of forward slashes: (/^./)

Basic Special characters and Symbols with in regular expressions:

'^' --> Anchor for the beginning of a line
'$' --> Anchor for the end of a line
'\A'-> Anchor for the start of a string
'\Z'-> Anchor for the end of a string
'.' -->Any character
'..'-> Any two characters
'\w'->Any letter, digit or underscore
'\W'->Any thing that '\w' does not match
'\d' ->Any digit
'\D' ->Any thing that '\d' does not match
'\s' -->White space
'\S'-->Non white space

Some examples:

To substitute first two characters of string :
"Hi Harini".sub(/^../,"Hello")
output : Hello Harini

Here '^' represents the beginning of a line, and '..' represents two characters. That means two characters starting from the line, that would be 'Hi' in our example. Method 'sub' will substitute the first argument with second.
Hi is substituted with Hello.

To substitite last six characters of a string :
"Hi Harini".sub(/......$/,"vamshi")
output : Hi vamshi

Here '$' represents the end of a line, and '......' represents six characters. That means six characters at the end of the line, that would be 'Harini' in our example. Method 'sub' will substitute the first argument with second.
Harini is substituted with vamshi.

Iterations :

To print single character at a time of a string:
"abcde".scan(/./){|x| puts x}
output :
a
b
c
d
e

Scan method looks through the string for anything that matches the regular expression passed to it.
'.' represents a single character, In our example regular expression looks for a single character at a time and prints them separately.

To print two characters at a time:
"Hi Harini, how are you".scan(/../){|x| puts x}
output :
Hi
H
ar
in
i,
h
ow
a
re
y
ou

Scan method looks through the string for anything that matches the regular expression passed to it.
'..' represents a two characters, In our example regular expression looks for a two characters at a time and prints them separately.
Note : '.' means any character that includes white spaces also.

To print two characters at a time with out including white spaces:
"This is a test".scan(/\w\w/) { |x| puts x }
output:
Th
is
is
te
st

Special characters denoted with back slashes have special meaning. '\w' means "any alphanumeric character or an underscore".
'\w' will consider the grouped characters.

To print digits in a given string:
"I have 20$".scan(/\d+/){|x| puts x}
output : 20

Regular expression that uses '\d' is to matchany digit, and the + that follows \d makes \d match as many digits in a row as possible.

with these examples try more with those listed in the table..

Monday, September 8, 2008

RESTFUL rails

RESTful Rails have been a a much debated part of the Rails core, since the original restful_rails plugin was merged in to core just over a year ago. But with the improvements that have been made in Rails 2.0, they are here to stay, so it is important to understand what they are, how they work and when to (and when NOT to) use them. This is actually a pretty big topic, and I think it is worth while giving you some background first, so I’ll split the post in twain - Part I is theoretical, Part II is practical. So get your network protocol hats on, and get ready to learn about the inner workings of the language of the web.

REST vs. CRUD

Where would the web be with out acronyms? REST stands for REpresentational State Transfer and describes resources (in our case URLs) on which we can perform actions. CRUD, which stands for Create, Read, Update, Delete, are the actions that we perform. Although, in Rails, REST and CRUD are bestest buddies, the two can work fine on their own. In fact, every time you have written a backend system that allows you to add, edit and delete items from the database, and a frontend that allows you to view those items, you have been working with CRUD.

rails

Welcome

About Me

Friendly and humanitarian Honest and loyal Original and inventive Independent and intellectual