Updated: February 12, 2013
A few weeks before every Pragmatic Studio course, we send out homework to help attendees prepare for the course. The homework includes instructions for getting any required software installed and tested on their laptop, and some recommended reading. Our goal is to make sure that everyone turns up on the first day ready to program. So we try to catch installation problems early and help folks through them. Sending out prep homework ahead of time also means that attendees can begin to experiment on their own. As a result, they often jot down questions to ask during our time together. In a way, our courses start the moment you register.
We're continually updating our homework to take into account new software versions and new ways of doing things. With the topics we teach, there's never a dull moment. For the Rails Studio in particular, we've been teaching Rails 3 for a while now. And although you can use Ruby 1.8.7 with Rails 3, it's better to use Ruby 1.9.
It seems a lot of folks are interested in making this transition. So we thought it might be helpful to share our recommended installation steps for Ruby and Rails.
Install Ruby 1.9 and Rails 3
The easiest way we've found to install Ruby, Rails, and other supporting software on Windows is using the RailsInstaller. It's a self-contained Windows installer (an .exe file) that includes a Ruby language execution environment, a baseline version of Rails, and other useful goodies such as Git, SQLite, and the Windows DevKit.
On the RailsInstaller page, click the big green "Windows Ruby 1.9" button to download the installer.
Once the executable installer has downloaded, use Windows Explorer to navigate to where you saved the .exe file and double-click it to start the installation process.
After stepping through a couple standard installer screens, you'll be prompted for the installation destination. By default, RailsInstaller will be installed in your C:\RailsInstaller directory. We'll assume you go with the default destination.
When the installation is complete, a command prompt window will open and prompt for your name and email. Then you'll end up in the C:\Sites directory. You should see a window with a blinking cursor and a prompt that looks something like this:
If this is the first time you've seen this command prompt it may seem rather intimidating, but don't let it throw you. It's simply a way to interact with your computer by entering commands. In fact, here comes our first command...
Open a new command prompt by selecting Start -> Run... and typing cmd into the dialog box. You should see a new window with a blinking cursor and a prompt that looks something like this:
Verify that Ruby 1.9.3 was successfully installed by typing
Ruby should reply with
ruby 1.9.3p392 (2013-02-22) [i386-mingw32]
Next, update Rails to the latest version by typing
gem update rails
Then sit back and relax as RubyGems downloads all the Rails-related gems and assembles the documentation. After a few minutes, you should end up with a dozen or so gems installed. If you see a warning about "file 'lib' not found" while it's generating documentation, don't worry about.
Finally, verify that the latest version of Rails was successfully installed by typing
Rails should answer with 3.2.13 or higher.
Create An Example Rails App
Now that we have all the required software installed, let's create your first Rails app to make sure everything is working in harmony. We'll create a simple application for managing a list of todos.
From a command prompt, navigate to a directory where you want the application code to live (your C:\work directory, for example).
Start by creating an empty Rails application called
rails new todos
Change into the
todosdirectory that was created in the previous step:
The application doesn't know about todos yet, so we'll use scaffolding to quickly generate all the code for managing a list of todos. Run the scaffold generator by typing
rails g scaffold todo name:string due_on:date completed:boolean
You'll see Rails create a bunch of files, including a migration file for creating a database schema to store todo items in a database (SQLite3 in this case).
Run the database migration by typing
Then start the Rails app by typing
When you're done, you can stop the Rails app by typing
CTRL-Cin the command prompt where you started the app.
That's all there is to it! Now you have everything you need to start building your own Rails apps. And that's how we recommend you start learning Rails, by building something, whether it be for fun or profit. Rails is all about helping you get from idea to deployment, fast!
You might also consider taking our online Rails course or scheduling a private course on-site at your location. You'll learn how to build a complete Rails app step-by-step, from idea to deployment. You'll come away with a solid understanding of the fundamentals of Rails, and how to put all the pieces together, so you can confidently create your first Rails app or jump right into an existing app!