Chapter 2. Organizing with Plugins
In most Rails books, this chapter comes last. It takes a lot of complicated examples to show why you need to organize your code at all. Examples at the beginning of books are simple enough that organizational strategies aren’t necessary. By the end of a book, if you get that far, it’s often too late for this sort of wisdom to be practical. Most readers, myself included, are actively programming while reading a new book for useful tips and insights and want to get to the meat of things right from the start. Unfortunately, the result of this pattern is that many Rails projects end up poorly organized. By the time you get to the chapter on code organization, you may already have a functioning application with millions of users (I hope this is your problem).
In this book, I’m going to break with tradition and present some high-level principles of code organization before we even write any code. Because of this “backward” presentation, some of what follows may seem unnecessary, burdensome, or even purposeless. Rest assured, the ideas that follow have none of these properties. They come from three years of incremental development of a 100% pure Rails website that, as of this writing, receives approximately two million unique visitors per month.
From this experience, I can tell you honestly that at some point, the amount of code you have will begin to strangle you. You may have started with a dozen classes, but a couple years down the road you have hundreds. ...
Get Enterprise Rails now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.