Adding a Wiki to MapMe.At using Gollum
I recently added a wiki on my MapMe.At site and found it quite tricky to get working and difficult to find just the right information I needed so I thought I’d write it up.
MapMe.At is still on Rails 2 which seemed to mean I couldn’t install Gollum as part of the site.
I created a separate Rails 3 project that runs alongside MapMe.At and simply hosts Gollum, using instructions from here: http://stackoverflow.com/questions/13053704/how-to-properly-mount-githubs-gollum-wiki-inside-a-rails-app
I wanted it to use the user information in MapMe.At’s session hash so switched MapMe.At to use activerecord based sessions and used information on here to make the rails 2 session load in rails 3: http://www.kadrmasconcepts.com/blog/2012/07/19/sharing-rails-sessions-with-php-coldfusion-and-more/
I’m not actually using the rails2 session as the main session, I just load the information in. I have the following in config/initializers/session_store.rb
module ActionController
module Flash
class FlashHash < Hash
def method_missing(m, *a, &b;)
end
end
end
end
MapmeAtWiki::Application.config.session_store :cookie_store, key: '_mapme_at_wiki_session'
Then in routes.rb:
class App < Precious::App
before { authenticate }
helpers do
def authenticate
oldsess = ActiveRecord::SessionStore::Session.find_by_session_id(request.cookies["_myapp_session"])
if oldsess and oldsess.data and oldsess.data[:user_id]
u = User.find(oldsess.data[:user_id])
email = "#{u.username}@gitusers.mckerrell.net"
session["gollum.author"] = { :name => u.full_name, :email => email }
else
response["Location"] = "http://mapme.at/me/login?postlogin=/wiki/"
throw(:halt, [302, "Found"])
end
end
end
end
MapmeAtWiki::Application.routes.draw do
# The priority is based upon order of creation:
# first created -> highest priority.
App.set(:gollum_path, Rails.root.join('db/wiki.git').to_s)
App.set(:default_markup, :markdown) # set your favorite markup language
App.set(:wiki_options, {:universal_toc => false})
mount App, at: 'wiki'
end
I wanted a wiki on the site to allow my users to help out with documenting the site. Adding their own thoughts and experiences and perhaps fixing typos I might make. I’m not sure that’s really started happening yet but at least I have a nice interface for writing the documentation myself!
Comments
— john