Preface

The Ruby on Rails phenomenon is sweeping through our industry with reckless disregard for established programming languages, longstanding conventions, or commercial support. You can get a whole lot of information on Ruby on Rails from articles on the Web, excellent books, and even formal coursework. However, there’s something missing. How does an established programmer, armed with nothing more than a little Ruby knowledge, go just beyond the basics, and be productive in Rails?

With Ruby on Rails: Up and Running, we are not going to reiterate the reference manual or replace Google. Instead, we’ll strive to give you the big picture of how Rails applications hold together and tell you where to go for the information that we don’t cover in the chapters. You will see how Rails dynamically adds features to all database models, called Active Record objects. By understanding the big picture, you’ll be able to make better use of the best reference manuals to fill in the details.

We won’t try to make you digest a whole lot of words. Instead, we’ll give you the theory in the context of an end-to-end application. We’ll walk you through the creation of a simple project—one that is a little more demanding than a blog or shopping cart, but with a simple enough structure that a Rails beginner will be able to quickly understand what’s going on.

We’re not going to try to cover each new feature. Instead, we’ll show you the ones we see as the backbone, forming the most important elements to understand. We will also cover migrations and Ajax in some detail, because you won’t find too much information on those two frameworks yet.

In short, we’re not trying to build a comprehensive Rails library. We’re going to give you the foundation you need to get up and running.

Who Should Read This Book?

Ruby on Rails: Up and Running is for experienced developers who are new to Rails and possibly to Ruby. To use this book, you don’t have to be a strong Ruby programmer. We do expect you to be a programmer, though. You should know enough about your chosen platform to be able to write programs, install software, run scripts using the system console, edit files, use a database, and understand how basic web applications work.

Conventions Used in This Book

The following typographic conventions are used in this book:

Plain text

Indicates menu titles, menu options, menu buttons, and keyboard accelerators (such as Alt and Ctrl).

Italic

Indicates new terms, URLs, email addresses, filenames, file extensions, pathnames, directories, and Unix utilities.

Constant width

Indicates commands, the contents of files, and the output from commands.

Constant width bold

Shows commands or other text that should be typed literally by the user.

Constant width italic

Shows text that should be replaced with user-supplied values.

Tip

This icon signifies a tip, suggestion, or general note.

Warning

This icon indicates a warning or caution.

Using Code Examples

This book is here to help you get your job done. In general, you may use the code in this book in your programs and documentation. You do not need to contact us for permission unless you’re reproducing a significant portion of the code. For example, writing a program that uses several chunks of code from this book does not require permission. Selling or distributing a CD-ROM of examples from O’Reilly books does require permission. Answering a question by citing this book and quoting example code does not require permission. Incorporating a significant amount of example code from this book into your product’s documentation does require permission.

You can get sample code at the main page for Ruby on Rails: Up and Running: http://www.oreilly.com/catalog/rubyrails/. You will find a ZIP file that contains the sample project as it exists after each chapter, with each instance of the sample application numbered by chapter. If you want to skip a chapter, just download the right ZIP file.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "Ruby on Rails: Up and Running by Bruce A. Tate and Curt Hibbs. Copyright 2006 O’Reilly Media, Inc., 978-0-596-10132-9.”

If you feel that your use of code examples falls outside fair use or the permission given here, feel free to contact us at .

Platforms

Ruby on Rails is cross-platform, but Unix and Windows shells behave differently. For consistency, we use Windows throughout the book. You can easily run the examples on the Unix or Mac OS X operating systems as well. You’ll see a couple of minor differences:

  • On Windows, you can specify paths with either the forward slash (/) or backslash (\) character. We’ll try to be consistent and use the forward slash to specify all paths.

  • On Windows, to run the various Ruby scripts that make up Rails, you need to explicitly type ruby. On Unix environments, you don’t. If you’re running Unix, and you are instructed to type the command ruby script/server, feel free to omit the ruby.

  • On Windows, to run a process in a separate shell, precede the command with start. On Unix and Mac OS X, append an ampersand (&) character to run the command in the background.

Safari® Enabled

When you see a Safari® Enabled icon on the cover of your favorite technology book, that means the book is available online through the O’Reilly Network Safari Bookshelf.

Safari offers a solution that’s better than e-books. It’s a virtual library that lets you easily search thousands of top tech books, cut and paste code samples, download chapters, and find quick answers when you need the most accurate, current information. Try it for free at http://safari.oreilly.com.

How to Contact Us

We have tested and verified the information in this book and in the source code to the best of our ability, but given the amount of text and the rapid evolution of technology, you may find that features have changed or that we have made mistakes. If so, please notify us by writing to:

O’Reilly Media, Inc.

1005 Gravenstein Highway North

Sebastopol, CA 95472

800-998-9938 (in the United States or Canada)

707-829-0515 (international or local)

707-829-0104 (fax)

You can also send messages electronically. To be put on the mailing list or request a catalog, send email to:

To ask technical questions or comment on the book, send email to:

As mentioned in the earlier section, we have a web site for this book where you can find code, errata (previously reported errors and corrections available for public view), and other book information. You can access this web site at:

For more information about this book and others, see the O’Reilly web site:

Acknowledgments

Writing a book is a demanding exercise, taking passion, commitment, and persistence. The authors on the cover get all of the glory (and possibly the blame). Many people contribute to a book. We’d like to mention the people who made writing this book such a fulfilling experience.

Collectively, Curt and Bruce would like to thank the outstanding team of reviewers who provided so many great comments, including David Mabelle, Mauro Cicio, Brooke Hedrick, Faisal Jawdat, Shane Claussen, Leo de Blaauw, Anne Bowman, Seth Havermann, Dave Hastings, and Randy Hanford. We’d also like to thank David Geary for fleshing out some of the early ideas in Photo Share.

Ruby on Rails: Up and Running would be nothing without the excellent contributions of the core Ruby on Rails team. We would like to thank David Heinemeier Hansson (the creator of Rails), Florian Weber, Jamis Buck, Jeremy Kemper, Leon Breedt, Marcel Molina, Jr., Michael Koziarski, Nicholas Seckar, Sam Stephenson, Scott Barron, Thomas Fuchs, and Tobias Luetke. Ruby is a fantastic language, and we would like to thank the many who made it so. We throw out specific thanks to Yukihiro Matsumoto (a.k.a. “Matz”), the creator of Ruby, and to Dave Thomas and Andy Hunt, without whom Ruby might have remained virtually unknown outside of Japan.

Bruce would like to specifically thank Curt, for stepping into this project after it seemed that it was dead. Also, thanks to those at AutoGas who were so instrumental in trying this technology within the context of a real production application—especially the core development team, including Mathew Varghese, Karl Hoenshel, Cheri Byerley, Chris Gindorf, and Colby Blaisdell. Their collective experience shaped this book more than you will ever know. Thanks to my Dutch friend Leo, again, for being such a supportive influence on this book, though you’re mostly a Java developer. You have had more influence on me than you might expect. More than anyone else, I would like to thank my family. Kayla and Julia, you are the sparks in my soul that keep the creative fires burning. Maggie, you are my inspiration, and I love you more than I can ever say.

Curt would like to thank his wife, Wasana, for letting him disappear behind his computer screen late into the night (and sometimes into the following day) without complaint. I would also like to thank my friends at O’Reilly, for giving me a forum to spread the word about the incredible productivity advantages of Ruby on Rails. Specifically, I’d like to thank chromatic for publishing my ONLamp.com articles, and Mike Loukides for not giving up when I kept telling him I didn’t want to write a book.

Get Ruby on Rails: Up and Running now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.