How to install Ruby On Rails running Xampp on Windows (hello world, Ruby!)


Hohoi…i’m so interested to write a post on my struggles to get my first Ruby on Rails work on Windows.
Thanks to internet which provided so many Guru who want to share their knowledge and skills.
Finally, this was a lot simpler than i had figured.
You may install Apache2 on windows or you may use some Apache2 install packages.
I picked XAMPP beside AppServ, Apache2Triad, WAMP just because i like packages included on it.
So here some step that i use,

1. install Xampp from ApacheFriends (http://www.apachefriends.org/en/index.html),
for a simpler download (http://www.apachefriends.org/download.php?xampp-win32-1.6.6a-installer.exe).
I install Xampp at c:\xampp

2. install Ruby (ruby186-26.exe or new version) from RubyForge ((http://rubyforge.org/projects/rubyinstaller/),
download an easy one-click Ruby installer, a self-contained installer that includes the Ruby language,
dozens of popular extensions, a syntax-highlighting editor and the book “Programming Ruby: The Pragmatic Programmer’s Guide

3. install Rubygem (rubygems-0.9.5.zip or new version) from RubyForge (http://rubyforge.org/projects/rubygems/)
tract it and then run ruby setup.rb

4. install Rails

gem update
gem install rails –include-dependencies

The install could take minutes which will show you like this message,
Bulk updating Gem source index for: http://gems.rubyforge.org

If you encounter an error like this,

Updating installed gems…
ERROR: While executing gem … (Gem::RemoteFetcher::FetchError)
getaddrinfo: no address associated with hostname.(SocketError)

then you must make sure you have internet connection
or may be your are behind a firewall.

When you don’t have internet at home or at office, then you will need
to go to a netcafe and download some files separately from rubyforge gems
(http://rubyforge.vm.bytemark.co.uk/gems/)

The following files need to download,
a. actionmailer
b. actionpack
c. actionwebservice
d. activerecord
e. activesupport
f. rails

Next, install it one by one,
gem install activesupport
gem install activerecord
gem install actionwebservice
gem install actionpack
gem install actionmailer
gem install rails

5. create a rails application
i create it at C:\xampp\htdocs\FirstProject, so run
rails -d mysql C:/xampp/htdocs/FirstProject

6. open C:\xampp\apache\config\httpd.conf file in a text editor,
scroll to the bottom and add the following,

#################################
Listen 3000
LoadModule rewrite_module modules/mod_rewrite.so

ServerName rails
DocumentRoot “c:/xampp/htdocs/FirstProject/public”
<Directory "c:/xampp/htdocs/FirstProject/public/"

Options ExecCGI FollowSymLinks
AllowOverride all
Allow from all
Order allow,deny
AddHandler cgi-script .cgi
AddHandler fastcgi-script .fcgi

#################################

7. start server with run this command,
cd c:/xampp/htdocs/FirstProject
ruby script\server

8. run the following at the command-line to keep from getting an “Unknown database” error,
rake db:create

10. make sure your connection to mysql can connect with right user and password,
set C:\xampp\htdocs\FirstProject\config\database.yml

11. to use Rails without a database, open C:\xampp\htdocs\FirstProject\config\environment.rb,
find the commented out line that reads,
# config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
remove the comment and you must remove the Active Record framework

Rails is a MVC (Model View Controller) framework, so all the output will happen in the controllers and views.

12. generate a controller named “hello” with an action “index”
ruby generate controller hello index

If you browsing to http://localhost:3000/hello, you will get
Hello#index
Find me in app/views/hello/index.html.erb

That message occurs because an action after “hello” doesn’t specified,
rails then search the “index” action and a view for this action doesn’t created too.

13. open the controller file at C:\xampp\htdocs\FirstProject\app\controllers\hello_controller.rb

Any public methods in a controller become actions in Rails. Notice the index action.
Add the following method just before end of file,

def world
@greeting = “hello world!”
end

The “@” sign lets views access the variable.

12. When browse to http://localhost:300/hello/world,
we have error like this,
Template is missing
Missing template hello/world.html.erb in view path C:/xampp/htdocs/FirstProject/app/views

13. “Template” is Rails word for the “View”. So Rails expecting the template at the path listed. Create or edit C:\xampp\htdocs\FirstProject\app\views\hello\world.rhtml, add the following text,

Try again, browse http://localhost:3000/hello/world and voila, “hello world, Ruby!”

Happy Rails developing and if you have any other learning resources that you’d like to share, please leave them in the comments!

4 Responses

  1. Damn, change this font …

  2. This font has ruined what is otherwise a good article.

    Frustratingly I can’t change the font with even a global CSS rule overriding font-family in firebug.

  3. Very Good article, I could never install RoR in Windows with Xampp whiout this article

    But I install ruby version 1.9.2 and some instruccions not work.

    For point 5
    rails -d mysql C:/xampp/htdocs/FirstProject
    I use
    rails new C:/xampp/htdocs/FirstProject

    At point 7
    ruby script\server
    I use
    rails server

    This page help in some errors
    http://guides.rubyonrails.org/getting_started.html

    bundle install
    resolve for me some problems in gem dependencies

    In the httpdconf i change some line as this

    The author
    AddHandler cgi-script .cgi
    AddHandler fastcgi-script .fcgi

    My httpdconf
    AddHandler cgi-script .cgi .rb
    #AddHandler fastcgi-script .fcgi

    Other instruccions that help me
    To know version
    ruby -v
    gem environment

    To know gem installed
    gem query –local

  4. […] dcided to try it out. Installation wasn’t as easy I expected. I was trying to follow: https://pandazen.wordpress.com/2009/10/21/how-to-install-ruby-on-rails-running-xampp-on-windows-hello… , but it doesn’t seem to work […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: