How Rails Works

Rails is a set of Ruby objects that together make up a framework. Installing Rails is a first step toward building an application, but while it gives you many useful objects that can run happily in a web environment, there’s a lot missing, a lot you have to provide.

You can buy a beehive—a set of boxes with frames that the bees will inhabit and fill with honey. It’ll have a top, a base, an entrance, a number of useful architectural features, and a nice coat of paint. It looks like a beehive when it’s set up. Unfortunately, setting up a beehive is just the first step. To make a beehive work, you have to add bees, who will finish building their home, collect useful nectar and pollen, and make the hive interact with the world.

Rails gives you an empty beehive. You don’t add bees, exactly, but you do populate it with your own logic. That logic turns Rails from an empty container into a dynamic application, connected to the outside world and performing the tasks you define.

The rest of this chapter will teach Ruby within the Rails framework, explaining the language in the context you’ll likely be using it.

Note

If you haven’t installed Rails yet, take a look at Chapter 1. It might be easiest to use Heroku, a web-based implementation that will spare you having to really install Rails before getting started. On the other hand, if you want to stay at the command line, you can also run much of this code in irb, the Ruby command-line interface described in Chapter 11 ...

Get Learning Rails: Live Edition 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.