How to Read This Book

The first part of this book makes sure you’re ready. By the time you’re done with it, you’ll have been introduced to Ruby (the language), you’ll have been exposed to an overview of Rails, you’ll have Ruby and Rails installed, and you’ll have verified the 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 (such as “here’s a chapter on models, here’s a chapter on views,” and so forth). These components are designed to work together, and each chapter in this section tackles 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).[6]

Be careful if you ever choose to copy files directly from the download into your application: if the timestamps on the files are old, the server won’t know that it needs to pick up these changes. You can update the timestamps using the touch command on either Mac OS X or Linux, or you can edit the file and save it. Alternatively, you can restart your Rails server.

Part 3, Rails in Depth, surveys the entire Rails ecosystem. This starts with the functions and facilities of Rails that you’ll 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. Finally, we survey a number of popular plugins that augment the Rails framework and make Rails an open ecosystem rather than merely a framework.

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 examples that you can download.

To help you find your way, if a code listing can be found in the download, you’ll see a bar before the snippet (like the one here):

 class​ SayController < ApplicationController
»def​ hello
»end
 
 def​ goodbye
 end
 end

The bar contains the path to the code within the download. If you’re reading the ebook version of this book and your ebook viewer supports hyperlinks, you can click the bar and the code should appear in a browser window. Some browsers may mistakenly try to interpret some of the HTML 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’ll also see some helpful little triangles to the left of the lines that you’ll need to change. Two such lines are indicated in the previous code.

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 particular 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 aren’t 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 guaranteed to be more up-to-date than the material in this book. If you install Rails using RubyGems (which we recommend), start the gem documentation server (using the gem server command), and you can access all the Rails APIs by pointing your browser at http://localhost:8808.

In addition, you’ll see that Rails helps you by producing responses that clearly identify any error found, as well as traces that tell you not only the point at which the error was found but also how you got there. You’ll see an example ​here​. If you need additional information, peek ahead to Iteration E2: Handling Errors, to see how to insert logging statements.

If you get really stuck, plenty of online resources can help. In addition to the code listings mentioned, you can find more resources on the Pragmatic Bookshelf site page for this book, including links to the book forum and errata.[7] The resources listed on these pages are shared resources. Feel free to post not only questions and problems to the forum but also any suggestions and answers you may have to questions that others have posted.

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

Footnotes

[2]

http://rubyonrails.org/doctrine/

[3]

http://agilemanifesto.org/

[4]

https://github.com/turbolinks/turbolinks/blob/master/README.md

[5]

http://guides.rubyonrails.org/engines.html

[6]

http://pragprog.com/titles/rails51/source_code

[7]

https://pragprog.com/book/rails51