Forum: Ruby on Rails How to display static html content using layouts in rails

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
07039fd832b0c5e9817c17581ed5f67b?d=identicon&s=25 Scott Sehlhorst (Guest)
on 2007-06-12 23:43
(Received via mailing list)
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
(or or whatever).

1) create the new controller: ruby script/generate controller static
2) assign a layout if not already assigned in application.rb: 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 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
This topic is locked and can not be replied to.