O'Reilly logo

Learning Rails 3 by Edd Dumbill, Simon St. Laurent, Eric J Gruber

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 2. Rails on the Web

Now that you have Rails installed, it’s time to make Rails do something—not necessarily very much yet, but enough to show you what happens when you make a call to a Rails application, and enough to let you do something to respond when those calls come in. There’s a long tradition in computer books of starting out with a program that says “hello” to the programmer. We’ll follow that tradition and pursue it a bit further to make clear how Rails can work with HTML. You’re welcome, of course, to make Rails say whatever you’d like.

Note

The work in this chapter depends on the hello application created in Chapter 1. If you didn’t create one, go back and explore the directions given there. You can also find the files for the first demonstration in ch02/hello01 of the downloadable code.

Creating Your Own View

Saying “hello” is a simple thing, focused exclusively on putting a message on a screen. To get started, we can post that message using a view including HTML that will get sent to the browser.

Rails actually won’t let you create views directly. Its controller-centric perspective requires that views be associated with controllers. While that might seem like a bit of an imposition, it’s not too hard to work around.

Creating anything in Rails requires going to the command line. Open a terminal or command window and go to the home directory of your Rails application.

Then type:

       rails generate controller hello index

rails generate’s first argument, controller, specifies ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required