1
O
c
t
o
b
e
r
2
0
0
5
Junctionbox Six
A quiet day at the office. One of those Friday’s when I didn’t feel like doing much client work. Instead I’ve been dabbling with the architecture for our new website.
The current website is based around a heavy maintenance custom-engineered CMS system, written in PHP. All we want to keep from that are the news articles and portfolio, both of which are driven from database tables.
Now that we know and love Rails, the easiest thing is to have a website that is essentially static, with exceptions being the bits that render the news and portfolio. Easy peasy. A couple of controllers and some scaffold is all that’s required.
What about the static content? One way is to have another table for pages, but then you cannot easily create content in something like Dreamweaver – you end up cutting and pasting all the time. Another alternative that lots of people use is to hook the Rails 404 error handler to bypass Rails and render the static page directly. Trouble with this is that you end up with duplicating template layouts (i.e. once for Rails, and again for outside of Rails) and you can’t integrate nice Rails or Ruby stuff inside such pages.
Instead I’ve a simple Page controller that looks up static content by filename, i.e. it isn’t derived from ActiveRecord. This controller reads the content from that file, then renders it using the application layout. As a result, you not only re-use the templates from Rails, but you get all the Rails goodies too available inside the page, which includes passing data from the page to the layout. Couple this with some dead simple routes mappings and everything is nice and readable.

Leave a Reply