I should mention I’m on Rails edge, currently revision 8168. Might work in earlier versions, but I didn’t try.
Install Markdown on Rails and the
I created a
config/initializers/template_handlers.rb file (that will also contain some Haml configuration) with this inside:
1 2 3 4
If you installed Markdown on Rails as a gem (I have it pistonized), I believe you need to require it first.
Routes and controller
Create whatever routes you want – perhaps
and create an
InfoController. My controller reads like so:
1 2 3 4 5 6 7 8 9 10 11
set_title method simply reads the view file, finds an initial header like
and sets that as the page title. It uses a
title= helper that I’ve defined in
ApplicationController. That method basically sets an instance variable that I display in my application layout. The net result is that the page
<title> will be set automagically from the Markdown.
set_title took some digging around inside Rails. There might be a nicer way to do this – let me know in the comments.
Markdown on Rails actually allows you to use erb in your templates, so if one doesn’t mind mixing things up and repeating oneself, one could get rid of
set_title and do e.g.
1 2 3
With all this set up, you can just create an
app/views/info/privacy.html.markdown like so:
1 2 3
The page title will be set and the Markdown is rendered all pretty inside the controller/application layout.