Ruby on Rails Installation and Oracle Database  Hot PDF Print E-mail
Tag it:
Delicious
Furl it!
Digg
NewsVine
Reddit
YahooMyWeb
Technorati
Articles Reviews Ruby
Written by Junaid   
Wednesday, 18 April 2007

{mos_sb_discuss:50}

1. WHY RUBY ON RAILS?

There are so many platforms available for Web application development like .NET or Java etc. but these languages are complex and they are also difficult to master. This is where you will find Ruby on Rails much better. If I have to put it in one line I will it is simple, easy and fast way to develop Web applications. You just need to install Ruby and the required packages and you can create a Web application in just a few minutes. You are not going to believe this unless you actually install Ruby. You do not have to compromise with the features; Ruby language is object oriented language like java

 

2. DEFINITIONS

What is Ruby?

Ruby is an object-oriented interpreted scripting language and was created by Yukihiro Matsumoto and since then it has grown in popularity world over and more so on being the language behind the Rails framework. The good thing about Rails is that you can start using it without extensive knowledge of the language; the Rails framework generates the basic classes needed for the Web application and uses reflection for object-relational mapping to the database.

What is Rails?

Rails is a Web application and persistence framework created by David Heinemeier Hansson. It includes the classes you need for creating database-backed Web applications that use the Model-View-Control (MVC) pattern.

Model-View-Controller Pattern (MVC)?

MVC design pattern separates the Web applications into Model, View and Controllers.

View: The way the data is presented to the user. In other words it is the format in which the data will be displayed to the users in a web-browser.

Model: Validation rules and Application data resides here.

Controller: It controls the Views and decides which View to be presented to the user based on the calculation of the data in the Model.

Rails Specific:

In the Rails framework, ActiveRecord acts as the Model. It maps database tables to Ruby objects and lets you traverse relationships between tables, get data and validate it.

The ActionView deals with the View and it decides the format of data displayed in the browser. Files that contain HTML and Ruby code are appended with an .rhtml extension.

What is OCI8?

It is the database driver for Ruby. It is similar to JDBC.

What is RubyGems?

RubyGems (or simply gems) is the packaging system used to package Rails components.

3. ORACLE DATABASE CONNECTIONS


Running Ruby on Rails using Oracle Database?

To run RoR Web application you need to install at least the following:

  1. Ruby
  2. Oracle SQL Plus
  3. Gem
  4. OCI8
  5. Rails

The Rails installation includes an application server sufficient for development and small implementations (WEBrick - for WEB server toolkit).

You can use your favorite text editor to edit source code files associated with your Web application.

To work with the OCI8 software you need to install Oracle Client and you must also configure the TNSNAMES.ora file with the connection information that lets the Oracle client software connect with the database.

Configuring an Oracle TNSNAMES.ora entry?

The TNSNAMES.ora file is a plain-text file which contains the information required for establishing connection to the DB. A typical TNS entry looks like this:

ORACL = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = servername)(PORT = 1521)) ) (CONNECT_DATA = (SERVICE_NAME = ORACL) ) )

4. INSTALLATION

Installing Rails and its dependencies?

First of all you must install Ruby and Gems. Now to install Rails and its dependencies:

gem install rails --include-dependencies

If you can’t connect to remote gems, download Rails from http://www.rubyforge.org and then install each gem locally. You can use following commands:

gem install .

For Example:

gem install actionmailer

How do I install Ruby on Rails on the Windows OS? 1.

Install Ruby

Simply download the Ruby and run the installer. You can verify the installation by running following command.

run gem list --local

And the output should be: fxri (0.3.2) Graphical interface to the RI documentation, with search engine. fxruby (1.2.6) FXRuby is the Ruby binding to the FOX GUI toolkit. sources (0.0.1)

This package provides download sources for remote gem installation

For more details check the Ruby on Rails Web site (http://www.rubyonrails.org/down).

2. Verify the Rails Installation

Use these commands:

rails –help

It will display the usage details and different options.

Usage: c:/ruby/bin/rails /path/to/your/app [options]...

5. CREATING AN APPLICATION

What are the Database Object Conventions required by Rails when using Oracle?

Two conventions are fundamental to Rails development:

There are two conventions:

Table names should be plural and Model object mapped to that table has same name but in the singular form.

A primary key of type NUMBER named id should be created for each table. This column will serve as the unique identifier used by Rails to retrieve records by default.

How do I create a basic Rails application?

You need to follow the following steps:

1. Configure the Database

Connect to the database you intend to use for the application through SQL*Plus and create your database objects.

2. Create the Rails Web application

Navigate to working directory and create a Rails application:

rails name_of_your_first_application

Subsequent commands will run scripts that are relative to the newly created application directory, so navigate to this directory using the following command:

cd name_of_your_first_application

3. Configure the application to use the Database

Edit the database.yml file found in the config directory. Delete the contents of the file and replace them with the Oracle-specific entries. Your file should look something like this:
  1. development: adapter: oci
  2. host: ORACL
  3. username: firstruby
  4. password: firstruby

4. Create the basic Model, Views, and Controller

Run the following command, which will create the scaffold (in essence, an entire skeleton Web application) based upon the table in the user schema:

ruby scriptgenerate scaffold model_name_here

5. Test the newly created application

First, start the (included) Web server:

ruby scriptserver

Now navigate to:

http://localhost:3000/plural_of_your_model_name_here

User reviews

There are no user reviews for this item.

Add new review




Powered by jReviews

Last Updated ( Thursday, 07 June 2007 )
 
< Prev   Next >