Aniruddha S Deshpande
Ruby on Rails
Ruby on Rails is an extremely productive web application framework written in Ruby by David
Heinemeier Hansson. This is a open source Ruby framework for developing database-backed web
applications. Ruby on Rails has gained popularity in the enterprise development community among
both programmers and system managers. As an open source platform, Ruby is proving to offer a
number of advantages for powering enterprise applications, not the least of which is a shorter
development time for robust applications and the creation of denser code that's easy to work with and
What is Ruby?
A High Level Programming Language
Interpreted like Perl, Python
Object-Oriented like Java
Easy to learn.
Open source (very liberal license) Rich libraries
Very easy to extend
Less Coding with fewer bugs
Large and Helpful community
What is Rails?
An extremely productive web-application framework.
Includes everything needed to create a database-driven web application using the Model-
Requires fewer total lines of code than other frameworks spend setting up their XML
You could develop a web application at least ten times faster with Rails than you could with a
typical Java framework.
Who is using Ruby on Rails?
Twitter, Scribd,Yellowpages,ThoughtWorks,Amazon,Cisco,Oracle,IBM ... see the link
Installing Ruby (Windows)
Download and Run the One-Click Installer from the following link:
Installing Rails (Windows)
Option 1> GUI based Rails
You can download InstantRails, which has everything (Ruby, Rails, MySQL v4) in it.
Option 2 (Recommended)> However, If you already have Ruby and some kind of DB installed, and
want to use that for Rails. Just type the following command in console (Ensure ruby is in the PATH
gem install rails --include-dependencies
This will install the latest version of Rails
Integrated Development Environment
1. NetBeans offers great features to develop Ruby/Rails Applications.
2. RadRails by Aptana is another very popular RoR IDE (free basic version)
3. Eclipse can also be used for RoR Development, but requires user to download a lot of packages.
The following article tells you, how to set up RoR Environment for Eclipse
Keeping Rails upto-date:
gem update rails --include-dependencies
RoR has a Model-View-Controller Architecture.
Model: Model maintains the 'state' of the application. It’s an interface to the Database Tables. Active
Record is the Rails package, which provides the ORM Layer on top the Database tables. When,
working with RoR, one interacts with Model objects for Database transactions, which are translated
to Database tables seamlessly by the ORM layer (Active Record).
View: The View is responsible for generating the user interface, based on data from the Model or the
Controller: Controllers receive events from the outside world (e.g. user input), interacts with the
Model, and displays an appropriate View to the user.
Action Pack is the Rails package that provides the library for View and Controller operations.
The following depicts the interactions in the MVC framework.
Creating a Sample Rails App:
One of the biggest advantages of using RoR, is the speed at which one can get a jump-start on
a project, enabling the customer to get a glimpse of the end product, in the very early stages of the
1. To create a rails project, simply type the following command in your desired workspace
You will see that Rails automatically creates a hierarchy of folders and other important files for you,
essential for any general project.
For example: Say, We want to create a project called 'demo'
C:rails_projects> rails demo
Now, go into the demo project root directory
C:rails_projects> cd demo
You will find a directory structure as follows:
Now, run the default web server that Rails ports with, by typing the command:
C:rails_projectsdemo> ruby script/server
You are done! Goto the following URL to access your application:
Rails will welcome you with the following screen:
Displaying 'Hello World!'
To write a simple Hello world app, we need just the controller and view code and not the model,
since we are not dealing with any DB yet.
So, create a controller called 'hello' by typing following command:
C:rails_projectsdemo>ruby script/generate controller hello
You will see that Rails automatically creates a HelloController in the controller folder, so open it in
your IDE and have a look at it. It will be like this:
class HelloController < ApplicationController
It’s an empty class that inherits from ApplicationController, so it gets all the default Controller
behavior from Rails. In order for the Controller to respond to user requests, we need to add 'action' to
Let’s add an action called 'world', which any user can call to get some response.
class HelloController < ApplicationController
Now, go to the following URL
The Rails URL follows a convention of domain/<ControllerName>/<ActionName>
But, you will get an error message, saying 'Template Missing', that is because the action does not
have an associated View, so Rails could not find it.
Note, that Each Controller will have a folder named after it in the Views folder.
So, go to the folder names 'hello' in the Views directory and create an html file called 'world.html'
Add some HTML code to display 'Hello World!' in it. Save it!
Now, again go to the same URL:
Done! Rails now shall display your 'Hello World!' message
Recommended Books (Must Buy)
1. Agile Web Development with Rails (By the creator of RoR)
2. Programming Ruby