“Hello, World” Web Application in Ruby on Rails using console
Installation and setup instructions of Ruby on Rails web framework on different operating systems is covered in the following posts:
- Setting Up Rails Development Environment on Windows Vista/XP
- Setting Up Rails Development Environment on Ubuntu GNU/Linux
- Setting Up Rails Development Environment on Fedora GNU/Linux
If you would rather use an IDE to develop Ruby on Rails applications, Aptana IDE is covered in "“Hello, World” Web Application in Ruby on Rails using Aptana Studio."
This post describes how to create a basic "Hello, World" web application in Rails using only console tools and a text editor. The instructions work pretty much the same for all operating systems with little to no modifications.
Make sure that you have the latest versions of all components installed:
ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-linux]
1.3.1
Rails 2.2.2
(Output text might be slightly different on Windows OS but the version numbers should be the same.)
To create a new rails project, run the following command which generates the required directory structure for a rails application:
# cd hello
# ls
app db lib public README test vendor
config doc log Rakefile script tmp
The purpose of each directory generated is more or less self-explanatory, like the test directory is for storing test files and the log directory contains various log files.
Rails application the scaffold generator way
Scaffolding allows us to generate template code necessary to directly run our application and play with it without having to write a single line of code. We can also open the generated files to take a peek at the generated code. We can then modify this code to our liking or just throw it away and write everything manually once we are satisfied with the prototype. The scaffolding code can be generated, say for a resource called 'person', by running the following command:
This command generates(among other files) a Rails migration file in db/xxx_create_people.rb which is responsible to create the database schema for our application; a model in app/models/person.rb; a controller in app/controllers/people_controller.rb and related view files in app/views/people directory. ('people' is used wherever plural of 'person' is needed.) Have a look at the code generated in the migration file:
-
create_table :people do |t|
-
t.string :name
-
t.string :password
-
t.string :email
-
t.integer :age
-
-
t.timestamps
-
end
Run the following commands to initialize the database:
# rake db:migrate
Now we are ready to run the application and use it. Start the WEBrick web server:
Open your favourite web browser and go to http://localhost:3000/persons url. You should see a page similar to the following screenshot(after I added couple of entries using the "New Person" link):

Also make sure you look at the code generated in the controller file and the various view files!
Read the official Getting Started with Rails guide.
Read more Rails articles on this blog.
This article is very good for the beginners on Rails.
QuoteComment by sharmila — May 18, 2009 @ 3:24 pm
[...] on Windows Vista/XP by tabrez. After that simple install (it worked!) I decided to go with “Hello, World” Web Application in Ruby on Rails using console another great post by tabrez. I have since mixed in some MongoDB usage and am getting a gem error [...]
QuotePingback by Pigs may not have wings, but I can Ride the Rails with a flu — November 11, 2009 @ 9:42 pm
first Ruby on rails Web application and using mysql databases (doin dome edition to database.yml) http://madhukaudantha.blogspot.com/2009/12/ruby-on-rails-web-application-with.html
QuoteComment by madhuka — December 14, 2009 @ 12:20 pm
Thanks for this self - explanatory introduction. its really gud for newbies
QuoteComment by Johnmark — March 10, 2010 @ 2:35 pm