February 17, 2011 | In: Hello World, Ruby on Rails
Getting to ‘Hello World’: Ruby on Rails on Windows
I’ve started playing with Rails. So far it looks really great. I get it. I do. The concept of Convention over Configuration – it makes a ton of sense. Here’s where you lose me Rails: how can I install/set up/get to ‘Hello World’?
I want to code. I don’t want to configure right? Ok, let’s say you’re new to .Net. What do you do?
- Download Visual Studio Express.
- File->New Project
- Write some code – Response.Write(“Hello World”);
- Hit F5
- Rejoice!
5 steps. One of those steps involves hitting a single button and another involves rejoicing.
Now let’s say you’re like me and you want to write a small Hello World Ruby on Rails app using the latest version of Ruby and the latest version of Rails.
Here is what you’ll need to do. Bit tricky. Doable yes, but someone (not it!) needs to write a nice wrapped up Windows MSI for this:
- Install Ruby from http://rubyforge.org/frs/?group_id=167 (version 1.92-p136 as of this writing). Version is crazy important in rails. Make sure you tick the box that adds Ruby to your PATH.
- Download and install Ruby gems, it’s like apt-get (or er, windows update?). It’s a package manager that lets you download stuff and keep it up to date.
- Get it here: http://rubyforge.org/frs/?group_id=126 (version 1.5.2 as of this writing)
- Extract it
- Figure out where you extracted it. Open a cmd prompt by going to Start->Run and typing ‘cmd’ and navigate to that directory by typing cd c:\downloads\ruby-gems or whatever your folder is
- once you are properly in the folder run ruby setup.rb
- Now gem is installed so we can install rails. At the cmd prompt run gem install rails. Pretty easy huh?
- Install the Sqlite gem (required to run your first rails ‘hello world’ app, even if you don’t want to use a database at all). For some reason there’s an issue with this on Windows. But it’s pretty easy to get going:
- At the cmd prompt run gem install sqlite3
- After the command completes, grab this zip: http://www.sqlite.org/sqlitedll-3_7_3.zip
- Get the extracted files an place them in your /ruby/bin/ directory where you installed ruby in step 1.
- Now we’re ready to create our first app. At your trusty cmd prompt run rails new /path/to/your/app
- Start your rails server by running cd /path/to/your/app followed by rails server. Now you can browse to http://localhost:3000 to see the default rails application
- Now Ruby on Rails is fully installed! Rejoi-er-what about ‘Hello World’? Ah yes, we still have not written a single line of code. Well, here’s where Rails shines a bit. Go back to your trusty cmd prompt and run rails generate controller Greetings hello This will actually generate a controller called ‘Greetings’ with an action/view called ‘hello’.
- For this simple example go to /path/to/your/app in Windows Explorer. Find the /app/controllers sub-directory. In there you should see your Controller – greetings_controller.rb. Edit the file in your favorite Ruby on Rails editor to look like this:
class GreetingsController < ApplicationController def hello @message = "Hellow world!" end end
- Now, let's edit our view. Back to the /app/views/greetings/ folder we'll see hello.html.erb. We can edit that to resemble:
<h1>Greetings#hello</h1> <p><%= @message %></p>
- Now, at last we can navigate to http://localhost:3000/greetings/hello
So now that I've been up and running with Rails almost a week I still think the setup was far and away the most challenging/least documented part. Which is what this post will hopefully solve for someone else down the line. Unfortunately, Rails changes so quickly that this will likely be out of date quite soon.
Ah, yes and lest we forget:
11. Rejoice

