This book is for web developers wanting to master two of the most promising recent developments in the field: Ajax and Ruby on Rails. By the end of this book, you'll be equipped with the knowledge to build richly interactive web applications with Rails.

Assumptions This Book Makes

This book assumes that you're familiar with the basic technologies used in building dynamic web sites, on both the client and server sides.

On the client slide, that means HTML/XHTML (which, for the purposes of this book, will be considered equivalent) and CSS. Extensive JavaScript knowledge isn't required, but you'll be well served by a refresher on JavaScript syntax.

On the server side, no specific language experience is assumed, but some grasp of the basic concepts is. If you have experience building web applications in a language like PHP, Java, or ASP, you'll have no trouble understanding the concepts behind Ruby on Rails. But, because this book doesn't cover everything there is to know about Ruby and Rails, you'll want to augment it with other resourcessuch as those recommended in Chapter 1.

Contents of This Book

This book can be roughly divided into three major parts, plus three complete example applications. The first part introduces all the tools and techniques of Ajax on Rails development, in a fairly linear fashion, from soup to nuts. The second part takes on a handful of larger themes (e.g., usability, security, testing) and provides an in-depth guide to each, in the context of Rails and Ajax. The third part is a comprehensive reference to Rails' two core JavaScript libraries, Prototype and

The first part, encompassing Chapters 1 through 5, is a tutorial. Each chapter builds on the previous, and each chapter balances theory and practice. Chapter 1 starts from scratchinstalling Ruby and Rails, introducing the fundamental concepts of Ajax development, and providing the context and rationale for the rest of the book. In Chapter 2, the idea is to take a walking tour, in baby steps, through some really simple Ajax examples. Rails provides a powerful suite of shortcuts for Ajax development. But to get the most out of them, it's essential to understand the "long" solution first; that's exactly the approach taken in Chapter 2. Chapters 3 and 4 introduce the shortcuts (Rails' helper methods), which are the workhorses of the Rails way. Lastly, Chapter 5 is the guide to the crown jewel of Ajax on Rails: RJS.

In the second part, we step back from the tutorial format and look at larger themes of professional web development. Chapter 6 deals with usability, cross-platform development, and how Ajax techniques relate to those problems. Chapter 7 coverslogging, testing, and debugging. Chapter 8 is on securityalways a consideration in web application development, especially when handling financial or other sensitive information. Performance and scalability are covered in Chapter 9. Snappy performance is often the most obvious benefit of Ajaxbut that doesn't mean performance issues don't arise.

The third part, Chapters 10 and 11, shifts into reference format. First up is Prototype, one of the most popular and elegant JavaScript libraries. Chapter 10 comprehensively tackles each method that Prototype provides. Chapter 11 covers, in the same fashionprimarily reference, with generous examples. Both Prototype and scriptaculous are central to Ajax in Rails, but they are also commonly used outside Rails. So these chapters are a valuable reference even if you're building Ajax applications in another server-side language.

Sometimes, the best way to master new technology is to go straight to the source. So the book ends with three complete, professionally designed example applications, each showcasing different Ajax techniques in the context of a real application.

Conventions Used in This Book

The following typographical conventions are used in this book:

Plain text

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


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

Constant width

Indicates commands, options, switches, variables, attributes, keys, functions, types, classes, namespaces, methods, modules, properties, parameters, values, objects, events, event handlers, XML tags, HTML tags, macros, the contents of files, or 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.

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

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.

We appreciate, but do not require, attribution. An attribution usually includes the title, author, publisher, and ISBN. For example: "Ajax on Rails by Scott Raymond. Copyright 2007 O'Reilly Media, Inc., 978-0-596-52744-0."

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

We'd Like to Hear from You

Please address comments and questions concerning this book to the publisher:

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)

We have a web page for this book, where we list errata, examples, and any additional information. You can access this page at:

To comment or ask technical questions about this book, send email to:

For more information about our books, conferences, Resource Centers, and the O'Reilly Network, see our web site at:

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


First, I'm honored to have Sergio Pereira's contribution of Chapter 10it's a tremendous boon to the book.

If not for my wife's tireless encouragement and valuable suggestions, I'd still be writing thisthank you, Brooke! I'm very grateful to the rest of my family, especially my parents, Doug and Katy. I'm also indebted to my editor, Michael Loukides, an invaluable guide through the process of writing this book. Thanks to Derek Di Matteo for his adept copyediting.

Thank you to these technical reviewers, whose expertise and attention to detail shaped the book significantly: John Aughey, Trey Bean, Jeremy Copling, Kevin Eshleman, Cody Fauser, Brian Ford, Thomas Fuchs, Erik Kastner, Thomas Lockney, Marcel Molina Jr., Tim Samoff, Brian Spaid, Sam Stephenson, and Bruce Williams.

Thanks to the Rails core team and all those who've contributed to Rails, Prototype, and

Lastly, thanks to Kansas City's fine coffee houses that supported this project with espresso and Wi-Fi: Broadway Café, Latté Land, and The Roasterie.

Ajax on Rails
Ajax on Rails
ISBN: 0596527446
EAN: 2147483647
Year: 2006
Pages: 103
Authors: Scott Raymond

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: