9

I'm trying to provide a gollum based wiki for my app by mounting it as a rack application inside my routes.rb file:

require 'gollum/frontend/app'

#Gollun config

gollum_path = Rails.root
Precious::App.set(:gollum_path, gollum_path)
Precious::App.set(:wiki_options, {:universal_toc => false})

TestWiki::Application.routes.draw do
  mount Precious::App, :at => "wiki"
end

The wiki is supposed to run at '/wiki' but everytime a go to this url it redirects me to /wiki/create/Home, and after a create a page it redirects me to /wiki/wiki/page_name.
Am I missing some option? is this even possible?

marcosbeirigo
  • 11,098
  • 6
  • 39
  • 57

1 Answers1

10

I'll share with you what I did to get it working just now. I actually started with your code above and tweaked it until I got it sorted. If you're still hacking on it, maybe it'll work for you.

In Gemfile:

gem 'gollum'

In routes.rb:

require 'gollum/app'

YourApplication::Application.routes.draw do
  Precious::App.set(:gollum_path, Rails.root.join('wiki').to_s)
  Precious::App.set(:default_markup, :markdown) # set your favorite markup language
  Precious::App.set(:wiki_options, {:universal_toc => false})
  mount Precious::App, at: 'wiki'
end

Then, and this is the most important part, create and initialize the wiki directory:

~/Sites/ams$ mkdir wiki
~/Sites/ams$ cd wiki
~/Sites/ams/wiki$ ls
~/Sites/ams/wiki$ git init .
Initialized empty Git repository in /Users/xxx/Sites/ams/wiki/.git/

Shut down the server, bundle install, restart the server, and hit /wiki.

Good Luck.

Edit 2014-11-06: The latest release of gollum has a slightly different directory structure than at the time of the original writing. I've updated the routes.rb sample to match the latest gollum and rails.

voxobscuro
  • 2,132
  • 1
  • 21
  • 45
  • Any suggestions for how this could work will multiple wikis? e.g. wiki/1, wiki/2 – Chris Apr 11 '13 at 16:16
  • 4
    I'd suggest sticking the `Precious::App` and `require` lines in `config/initializers/gollum.rb`. – Kris May 15 '13 at 12:57
  • 2
    This doesn't seem to work anymore. Breaks with the error `bin/rails:6: warning: already initialized constant APP_PATH ` – Anurag Ramdasan Feb 09 '14 at 10:54
  • @Anurag, do not copy `Ams::Application.routes.draw`, put all `Precious::App` inside your `YourApp::Application.routes.draw`. Anyway in current version require path must be fixed `require 'gollum/app'`. – slowpoke Nov 06 '14 at 13:10
  • I've update the code sample above to match a little better. Hopefully it clears up any confusion. – voxobscuro Nov 06 '14 at 17:31
  • Excuse me, what does `Precious::App` do? I didn't find it in API doc. It's neither on middleware list. – knh170 Mar 30 '16 at 00:43
  • @knh170 Precious::App is the internal sinatra rack application that serves Gollum. see: https://github.com/gollum/gollum/blob/master/lib/gollum/app.rb#L48 and https://github.com/gollum/gollum/wiki/Gollum-via-Rack – voxobscuro Mar 30 '16 at 23:20
  • @voxobscuro thanks, yet another question: did anyone spot unexpected behaviors after mount gollum to `/wiki`?Run it at `/` root works just fine. As I found problems doing so: https://github.com/gollum/gollum/issues/1121 – knh170 Mar 31 '16 at 03:50
  • this doesn't work for Rails 5 unfortunately /Users/user/.rvm/gems/ruby-2.3.1@hspace/gems/railties-5.1.4/lib/rails/engine.rb:579:in `unshift': can't modify frozen Array (RuntimeError) – Mikhail Chuprynski Sep 28 '17 at 12:21
  • The not yet released 5.x branch seems to work with Rails 5.2. Change the gemfile to pull the repo from github until release: `gem 'gollum', github: 'gollum/gollum', branch: '5.x'` – Arctodus Oct 17 '18 at 15:03
  • Would like to add that this doesn't quite work out of the box anymore and a `bundle update` is required (I believe specifically to update the version of RubyPython). Just had me stuck for a bit, thought I'd share with anyone else trying – Diericx Sep 29 '20 at 21:49