How to display static html content using layouts in rails

Need: Include an “about page” in a ruby on rails site.
Goal: Minimize hassle, maximize DRY (e.g. nav menus, sidebars, etc)

Approach: Create a trivial controller, designed solely to present
static (or dynamic) content.

Assumptions: You have a working ruby on rails application at
www.example.com
(or example.com/app/ or whatever).

Steps:

  1. create the new controller: ruby script/generate controller static
  2. assign a layout if not already assigned in application.rb: layout
    “standard-layout”
  3. create an empty action : def about end
  4. create action.rhtml - put all the content in here. - it gets
    wrapped with the layout
  5. add a mapping in routes.rb: map.connect ‘about’, :controller =>
    “static”, :action => “about”

Notes: you can also do any dynamic rails stuff in the “static” page,
or use content_for to modify the standard layout, or whatever.

The mapping (5) tells rails to send www.example.com/about/ to your
“static” controller (you can name it anything), and the “about” action
(the names don’t have to match). The rhtml file (4) holds the html
you want presented - and any dynamic code you want to include will
work here too. The action (3) tells rails to render the rhtml file
(4) when called via the mapping (5). The content (4) is wrapped in
the layout (2).

The answers that I found to this problem (for my site) were not really
clearly spelled out for ruubs like myself. Just thought I’d give back
a little. Hope this gets indexed well and helps someone.

Scott Sehlhorst
http://tynerblain.com/nexus/about