• 沒有找到結果。

How To Read This Book

The first part of this book makes sure that you are ready: by the time you are done with it, you will have been introduced to Ruby (the language), have been

HOWTOREADTHISBOOK 23

exposed to an overview of Rails itself, have both Ruby and Rails installed, and have verified this installation with a simple example.

The next part takes you through the concepts behind Rails via an extended example—we build a simple online store. It doesn’t take you one by one through each component of Rails, here is a chapter on models, here is a chapter on views, and so forth. These components are designed to work together, and each of the chapters in this section tackle a specific set of related tasks that involve a number of these components working together.

Most folks seem to enjoy building the application along with the book. If you don’t want to do all that typing, you can cheat and download the source code (a compressed tar archive or a zip file).2

The third part of the book, starting on page278, surveys entire Rails ecosys-tem. This starts with the functions and facilities of Rails that you will now be familiar with. It then covers a number of key dependencies that the Rails framework makes use of that contribute directly to the overall functionality that the Rails framework delivers. Then there is a survey of a number of pop-ular plugins that augment the Rails framework and make Rails a platform rather than merely a framework. Finally, there is a list of components that can be used as replacements for components of the framework that either are core or defaults that have been selected for you. This makes Rails an open ecosystem rather than merely a platform.

Along the way, you’ll see various conventions we’ve adopted.

Live Code

Most of the code snippets we show come from full-length, running exam-ples that you can download. To help you find your way, if a code listing can be found in the download, there’ll be a bar above the snippet (just like the one here).

This contains the path to the code within the download. If you’re reading the ebook version of this book and your ebook viewer supports hyper-links, you can click the bar, and the code should appear in a browser window. Some browsers (such as Safari) will mistakenly try to interpret

2. http://pragprog.com/titles/rails4/source_codehas the links for the downloads.

Report erratum this copy is (B8.0 printing, September 9, 2010)

Prepared exclusively for Jared Rosoff

HOWTOREADTHISBOOK 24

some of the templates as HTML. If this happens, view the source of the page to see the real source code.

And in some cases involving the modification of an existing file where the lines to be changed may not be immediately obvious, you will also see some helpful little triangles on the left of the lines that you will need to change. Two such lines are indicated in the previous code.

Ruby Tips

Although you need to know Ruby to write Rails applications, we realize that many folks reading this book will be learning both Ruby and Rails at the same time. Chapter4, Introduction to Ruby, on page63, is a (very) brief introduction to the Ruby language. When we use a Ruby-specific construct for the first time, we’ll cross-reference it to that chapter. For example, this paragraph contains a gratuitous use of:name, a Ruby sym- :name

֒→ page64

bol. In the margin, you’ll see an indication that symbols are explained on page64.

David Says...

Every now and then you’ll come across a David Says... sidebar. Here’s where David Heinemeier Hansson gives you the real scoop on some par-ticular aspect of Rails—rationales, tricks, recommendations, and more.

Because he’s the fellow who invented Rails, these are the sections to read if you want to become a Rails pro.

Joe Asks...

Joe, the mythical developer, sometimes pops up to ask questions about stuff we talk about in the text. We answer these questions as we go along.

This book isn’t meant to be a reference manual for Rails. Our experience is that reference manuals are not the way most people learn. Instead, we show most of the modules and many of their methods, either by example or narratively in the text, in the context of how these components are used and how they fit together.

Nor do we have hundreds of pages of API listings. There’s a good reason for this—you get that documentation whenever you install Rails, and it’s guaran-teed to be more up-to-date than the material in this book. If you install Rails using RubyGems (which we recommend), simply start the gem documentation server (using the commandgem server), and you can access all the Rails APIs by pointing your browser athttp://localhost:8808. You will find out on page281 how to build even more documentation and guides.

Let’s get started! The first steps are to install Ruby and Rails and to verify the installation with a simple demonstration.

HOWTOREADTHISBOOK 25

“Agile Web Development with Rails...I found it in our local bookstore, and it seemed great!”

—Dave’s mum

Report erratum this copy is (B8.0 printing, September 9, 2010)

Prepared exclusively for Jared Rosoff

HOWTOREADTHISBOOK 26

Part I