I presume that you want the Markdown to be rendered. If you simply serve it up from your public
directory, then Rails won't render it.
What you could do is an a new controller, say WikiController
, which could render markdown files that you store somewhere like lib/wiki
. I haven't tested any of this directly, so you should take it only as a guide, but it should work okay.
The controller might look like something like this:
# app/controllers/wiki_controller.rb
class WikiController < ApplicationController
def show
page = File.open(File.join(Rails.root, 'lib', 'wiki', "#{params[:page_id]}.md"), 'r') { |f| f.read }
markdown = Redcarpet::Markdown.new(Redcarpet::Render::HTML, :autolink => true)
render :html => markdown.render(File.join(Rails.root, 'lib', 'wiki', "#{params[:page_id]}.md"))
end
end
And you could add a route like this:
# config/routes.rb
map.connect 'wiki', :controller => 'wiki', :action => 'show', :page_id => 'home'
map.connect 'wiki/*page_id', :controller => 'wiki', :action => 'show', :as => :wiki
The first route handles your special case (home.md
) and the second will allow you to structure your wiki however you like (including placing files in subdirectories, etc). Linking to /wiki/help/getting_started
will try to render the file lib/wiki/help/getting_started.md
.
You also have a link helper method, so that if you need to link to a wiki page from within your app you can call wiki_path(:page_id => 'help/getting_started')
.
This solution assumes you're using RedCarpet for Markdown rendering, however you could switch up any renderer you like.