Friday, February 4, 2011

Hello World – Ruby on Rails

None of tutorials i found around web helped me get straight to the Ruby on Rails development environment in Windows. that’s why i thought would sum up how i setup rails in my Windows XP Professional box.

Yet, this was amusing (from Ruby on Rails Getting Started Guide)

If you’re working on Windows, you should be aware that the vast majority of Rails development is done in Unix environments. While Ruby and Rails themselves install easily using for example Ruby Installer, the supporting ecosystem often assumes you are able to build C-based rubygems and work in a command window. If at all possible, we suggest that you install a Linux virtual machine and use that for Rails development, instead of using Windows.

Let’s start.

1. Rails Development Environment Prerequisites/Setup

you should have following things installed before you can ride on Rails

- Install Ruby Language
- RubyGems Packaging System
- A working installation of the SQLite3 Database. you can setup other databases later.

Ruby Installer bundles all ruby development environment within one click setup file. Download the latest version of Ruby Installer from this page: http://rubyinstaller.org/downloads/

i downloaded : Ruby 1.9.2-p136

it installs Ruby, Ruby Gems etc.. in your selected drive. don’t forget to check the “Environment path tick mark” during installation, that helps later.

Check installed components going to the program listing in Start Menu-> All Programs

add the Ruby Installation path to the SYSTEM or USER PATH eg path.  C:\Ruby192>

 

2. Verify the Ruby and RubyGems Installation

Go to Command Prompt  (Run->CMD)

Verify your environment variables i.e PATH is setup correctly otherwise we may run into problems.

Type following commands:

ruby –v 

should give you ruby version

and

gem –v

should give you gem version

in my case:
ruby version : 1.9.2
gem version: 1.5.0

if you didn't get these numbers, update gem, execute following command

gem update --system



takes few minutes to update your gem package.



3. Now Setup Rails



execute the following command in command line




gem install rails




it will install rails, takes few minutes. you can take a cup of coffee while rails gets completely installed.



check rails version after installation:




rails –v




gives you rails installation version. a long number looks scary.



4. Setup Sqlite3 database



execute following command:




gem install sqlite3-ruby




the installed sqlite3 gem requires sqlite3.dll file. you need to download, copy/cut/whatever –then- paste the sqlite3.dll file to your Ruby or system path.



Go to Sqlite download page http://www.sqlite.org/download.html 
Scroll down to “Precompiled Binaries For Windows”


Download the “This ZIP archive that contains a DLL for the SQLite library version 3.x.y



Extract the zip, copy the sqlite3.dll  to system PATH




That’s it.



5. Create your first Rails application : The New Hello World “Ruby on Rails”



create a special folder somewhere in you hard disk dedicated to rails project.

eg. D:\web\rails





Change working directory to that path. execute following command:




rails new the_new_hello_world




the_new_hello_world <—this is the name of the web app we are going to create. name it whatever you like.



if everything went fine, rails will create a “web app template” folder in your current directory i.e the_new_hello_world directory with bunch of files/folders, yes they suck.



6. Run the development web server



execute following command:




rails server




hurray! your development web server will be now running : http://localhost:3000/





Go to that page at http://localhost:3000/ . It is there to welcome you to Rails, follow the instruction under Getting Started Section.



1. Use “rails generate” to create your models and controllers


2. Set up default route and remove or raname the config/routes.rb file


3. Create your database





Continue reading the Getting Started Guide after successfully  setting up the rails environment.  http://guides.rubyonrails.org/getting_started.html





Congratulations!!!



you are now riding on rails. where are you going?





Mention me if it didn’t work for you. i might help.


Cheers.