1.6. Whetting Your Appetite

A "Getting Started" chapter would not be complete without an example to show you how quickly applications can be prototyped thanks to Rails. The aim of this section is truly to "whet your appetite" as opposed to provide extensive explanations of each step. In Chapter 5, after covering the Ruby language in Chapters 3 and 4, you'll create a more complex Web application and everything will be explained in detail. Here I'm going to provide you with a sneak preview. After all, Rails became so popular thanks also to its ability to create entire applications with just a few commands.

Begin by creating a Rails project that can hold your friends' addresses. From within a directory of your choice (for example, c:\projects), use the command prompt to run the following commands:

rails addressbook
cd addressbook

This generates an addressbook directory that contains the skeleton of your Rails application, and the second instruction makes it the current directory in your prompt.

This being Rails, you'll use a table within a database to store the data. This table will need fields like the person's name, address, phone number, and perhaps email and blog/site URL.

You can specify those fields and their data types thanks to the so-called scaffold generator, as follows:

ruby script/generate scaffold person name:string address:string phone:string
 email:string blog:string

This will generate a model, controller, and a series of view templates required to provide you with ...

Get Ruby on Rails® for Microsoft Developers 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.