Preface

On January 31, 2006, after over a year and a half of working with Flex and more than six months of playing with Rails (building toy apps, reading Agile Web Development with Rails, and so on), I finally realized that for many applications Rails was the perfect server-side technology to complement Flex—and on the flip side, that Flex offered capabilities that were either difficult, impossible, buggy, or merely annoying to do with JavaScript/AJAX/DHTML on the client side (especially if, like me, you’re not a JavaScript guru like Thomas Fuchs). Despite the productivity of Rails, at the end of the day we’re still dealing with the joys of HTML, JavaScript, CSS, and browser compatibility issues.

So, I did what I always do whenever I have a Really Great Idea: I registered a domain name. I wanted a name that would be good for promoting a possible book about using Flex and Rails together, so the natural choice was flexiblerails.com. I also got flexiblerails.net and .org because I was so sure how good an idea this was. By January 2006, the massive success of Agile Web Development with Rails had put dollar signs in the heads not only of publishers but also of many in the Rails community who had blogs. After all, writing a book couldn’t be much harder than writing a few blog posts, right?

I then did what I typically do whenever I have a Really Great Idea: nothing.

Between the demands of my job and my two-year-old son, I was too busy, too tired, and so forth. Besides, I had a lot of Really Great Ideas (and domain names to go with them), and I wasn’t acting on any of them.

So, time passed.

Then, it was announced that the Flex 2 SDK would be free (as in beer), and I thought again: Yep, Flex and Rails will be perfect together, especially because Flex 2 will be so much better than Flex 1.5.

Again: nothing. I’m too busy; I’m too tired; I’d rather play Civ 4; the list went on.

Then, Flex 2 went through its beta cycles and was released, with Flex Builder costing only $499, half of what had been expected.

Again: nothing.

Then, in July 2006, I stumbled upon an excellent tutorial by Stuart Eccles on liverail.net which had been written on April 16, 2006, about using Flex and Rails together, and then upon another one (written on the same day!) on Christophe Coenraets’ blog, and I realized that I wasn’t alone in thinking this really was a Really Great Idea—and that if I was ever going to write anything about it, I’d better get off my butt and do it now.

NOTE:

The ironic thing was that the liverail.net tutorial rails application was called (you guessed it) flexiblerails. For me, this was truly the “get off your butt and do something, you moron” moment: The first really good tutorial about Flex and Rails together used the same name for its example application that I had registered as a domain name months earlier! (If anyone cares: I registered flexiblerails.com on January 31, 2006. Stuart Eccles published part 1 of his excellent tutorial on April 16, 2006, and I had missed seeing it until July 2006!) If I hadn’t loved my domain name so much, I would have named this book something else, so as not to cause confusion between this book and the tutorial on his blog. I hope that this chronology is a sufficient acknowledgment of—and even an homage to—his tutorial: This book would not exist if his tutorial hadn’t motivated me to finally do what I had already thought of doing.

I released the first Alpha Version of this book in self-published form in September 2006. It was buggy and had terrible formatting for the code samples. Despite this, I got amazing feedback from many readers, which led to a much better book as a result. Over the year that followed, I released numerous revised Alpha and then Beta versions, adding iterations, updating Rails versions, rewriting the entire book, and so on. Throughout this process, my readers were remarkably helpful and patient, even though the roadmap for the book kept changing almost monthly.

As the book got better and more popular, publishers became interested. Manning approached me and we worked out a contract that ensured I could keep all of my promises to my existing readers while working with Manning to revise the book. During this time, Flex 3 went to Beta 2, and Rails 2 went to pre-release status. So, I rewrote the book again, this time using Flex 3 and Rails 2. The book doesn’t use all the new features, but it does use some of them, the RESTful URLs are correct, and so on. During the author review process, I did yet another pass through the code, re-creating all the code samples by following along with my own book, using Release Candidate 1 of Rails 2 (1.99.0). Then, just after the book went into typesetting, Rails 2 final (2.0.1) was released. So, during typesetting, I did yet another pass through the book, following along again using Rails 2.0.1. So, while the text of the book refers to Rails 1.99.0, rest assured that it has been tested with both Rails 1.99.0 and Rails 2.0.1.

This book has been part of my life for almost two years, consuming countless evenings and weekends. My sincere hope is that it will be an enjoyable read for you, and that you can build something great using the code written in it as the foundation.