Chapter 1. Starting Up Ruby on Rails

Before you can use Rails, you have to install it. Even if it’s already installed on your computer, or you opt to use a web-based development environment, there are a few things you’ll need to do to make it actually do something visible. In this chapter, we’ll take a look at some ways of installing Ruby, Rails, and the supporting infrastructure, and get a first, rather trivial project up and running.

To get you started, we’ll set up three different environments for running Rails: Heroku (the fastest option for getting started, which lets you develop applications online), Instant Rails on Windows, and the classic command-line version. Feel very welcome to jump to whatever pieces of this section interest you and skip past those that don’t. Once the software is working, we’ll generate the basic Rails application, which will at least let you know if Rails is working.

If you want to jump into learning Rails without getting hung up on installation, Heroku is likely your easiest approach, with Instant Rails a close second for Windows users. They both create an insulated environment separate from the rest of what your computer might have, and they require minimal configuration. If the classic command-line approach doesn’t appeal to you, or causes you problems, definitely give Heroku or Instant Rails a try. However you decide to set up Rails, in the end you’re going to need to install a structure like that shown in Figure 1-1.

Note

All of these options are free. You don’t need to spend any money to use Rails, unless maybe you feel like buying a nice text editor.

Getting Started in the Online Cloud: Heroku

Rails is hot, and cloud computing is hot. Why maintain your own server when you could have Amazon run your applications in a “cloud” of servers? And why not develop your Rails applications on the Web, instead of dealing with configuration details on your own computer?

The many components of a Rails installation

Figure 1-1. The many components of a Rails installation

The folks at Heroku (http://heroku.com) have created a web-based development framework for Ruby on Rails applications. Right now, it’s free, though it’s a beta, and betas are always risky. Its business model seems to lead to the paid hosting of running apps, so the development part might even stay free if all goes well.

Rather than downloading Heroku, you sign up. It’s a little buried in the beta version, but if you visit http://heroku.com and click on Login, you’ll find a “Sign up” link. It’s a limited beta, but the wait times have been pretty reasonable. (As of this writing, it says “less than a day.”) Once you’re signed in, you can go to “My apps” and click on “Create new app.” A few sections later, you’ll see your application development environment, something like Figure 1-2.

Heroku’s Code tab, where you start, looks pretty much like a set of file directories. You can navigate directories and open and edit files using Heroku’s built-in editor. The downward-pointing arrows next to the directory names bring up menus for creating and managing files. Below the directory list, the Revisions >> link lets you see what you’ve changed lately and commit changes to keep more precise track of what’s changed.

Across the top, the Data tab gives you access to the databases you’ll be creating, and Logs takes you to the log files recording the activities of your application. The fast-forward button (>>) on the top right will actually run your application. By default, it’ll look like a customized version of Figure 1-10, made a little more specific to Heroku, as shown in Figure 1-3.

A brand new Rails application development environment, in Heroku

Figure 1-2. A brand new Rails application development environment, in Heroku

At the bottom of Figure 1-3, you can see the rewind button (<<), which will take you back to the development environment. There’s one more piece you need to find before proceeding into Rails development, which is the gear button near the bottom of the left column. If you click on it, as you can see in Figure 1-4, you’ll get a menu of options for performing tasks you would normally have done from the command line.

Signs that Rails is running

Figure 1-3. Signs that Rails is running

The Heroku gear menu

Figure 1-4. The Heroku gear menu

The gear menu gives you access to many of the Rails tools that are normally used from the command line. Most of the rest of this book describes using them that way, because both Instant Rails and more traditional installs usually work that way. Just remember that in Heroku, ruby script/server means clicking the >> button, and that script/generate, script/console, and rake are run as the Generate, Console, and Rake commands from the gear menu. Gems and plug-ins, which you’ll use to extend Rails, can be installed from the Gems and Plugins>> menu item under the vendor directory.

And don’t worry—you’re not locked into Heroku. You can develop applications elsewhere and bring them in, or develop them in Heroku and export them. The settings for your application, shown in Figure 1-5, also let you make your apps public or private, make snapshots, or destroy your application if you don’t like it.

Application settings in Heroku

Figure 1-5. Application settings in Heroku

If you’re looking to experiment with Rails and want to get started quickly, Heroku can be a great option, whether or not you want your application to reside “in the cloud.”

Note

If you like Heroku but find the web interface constraining, a command-line set of tools and an API are also available. You can find more information at http://rubyforge.org/projects/heroku/ or at http://technicalpickles.com/posts/playing-with-heroku.

Get Learning Rails now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.