views:

189

answers:

2

I'm creating a personal site with Ruby on Rails. For the most part, RoR is the perfect tool, allowing for blog posts, comments, etc all rather easy.

However, I want to have a few pages that don't require any specific model. An 'About Me' page, for instance, is necessary, and yet doesn't warrant it's own model/controller. In addition, these 'singleton' pages will be linked to from my default layout, and must be accessible even when there are no objects created.

Is there a good way to handle this? I've seen many RoR sites that have single pages while maintaining pretty urls, but never an example of how it's structured. Finally, is it possible to make these single pages dynamic? I'd rather not have static html if at all avoidable.

+7  A: 

There's a Railscast about this subject which might answer your question:

http://railscasts.com/episodes/117-semi-static-pages

I've used this solution a few times in my Rails applications.

Eifion
Perfect, thanks! Seems robust and clean.
NolanDC
+1  A: 

I usually create a "static" controller, for instance an AboutController.

ruby script/generate controller about

Then I create as many action as my about pages: index, contact, terms... Then I add a generic route in my routes.rb file.

map.about 'about/:action', :controller => "about"

In my pages, I reference a single page as

<%= link_to "Contact", about_path(:action => "contact") %>

Because they are static pages, you can also consider to cache them in your controller.

class AboutController < ApplicationController
  caches_page :index, :contact, ...
end

This architecture fits well for the most part of static pages. If you want "semi-static" pages you might consider to dynamically load the content from the database.

Simone Carletti