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.
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 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.
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.
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.
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.