Modular Page Assembly in Rails

So, you’ve read “Agile Web Development with Rails,” and you’ve started to tinker with some pages on your own, but you just can’t figure out how you’re supposed to use that view file to create your 3 column layout?

So far I’ve found every tutorial on Rails talks about the default chain of controller to view to layout and stops. 3 files, done. Well, then what?

I felt your pain. So, I’ve prepared an article and sample code set (links up top) intended to pick up where AWDWR leaves off in explaining how to organize files for a modular page assemby approach with layouts and partials.If you’ve come from a template-driven web application framework, the way Rails builds pages can feel a bit backwards. For me, I was accustomed to the exact opposite of how Rails works. I’m used to the layout being the starting point, and its structure determining which view fragments the framework would include (based on dynamic file name conventions).

By the time I get to writing code for a site I have a pretty solid idea of how it will look, and how it needs to be structured. While AWDWR is a good intro, it left me feeling like I still had no idea how I was going to build typical modular web pages using layouts with reusable panels. Only after I figured this out was my brain going to feel free to work on the logical side of Rails.

So, I focused on solving that puzzle before I went much further. Out of that process, you get my first article about Rails. (I’ve written quite a bit about another language called Lasso).

Rails 2.x changes some things like file extensions. The article isn’t updated for these new details, but for the most part everything seems to still work for 2.x code as I’ve continued to use these techniques in Rails 2.3.


Download (387.5 KB) : modular_page_assembly_in_rails.pdf

The complete 10-page article in PDF.

Download (88.3 KB) :

Includes a source code example of the techniques discussed in the article.

The article explains a variety of techniques for combining layouts, partials, and views to create modular page assembly processes. Illustrations like the fragment shown above show the file organization, and source code is shown and explained.