Introduction
Its been a while since we’ve posted. That’s because we’ve been busy preparing for our beta launch. Toward that end, we’ve hired Rob Kaufman of Notch8 to strengthen our development effort. This post is about one of the plugins that has come out of that work, wiki_column.
wiki_column, allows you to add wiki functionality to any (textual) attribute of any model. Wiki links in that text will then refer to the model that you define as your wiki, the wiki model defaults to WikiPage. Any attribute you define as a wiki_column, will also get textile formatting automatically, for this reason wiki_column requires the RedCloth gem.
How to install it
Let’s assume you want to add a wiki to your Rails app (why else would you be here?). Let’s also assume that you have a Product model that has a description attribute that would like wiki enabled. Given those assumptions, we’ll start at the beginning. First install the RedCloth gem:
Next install the wiki_column plugin.
Next generate your WikiPage model and your Product model.
Don’t forget to migrate.
Now we add the wiki functionality to your models, and validate that our slugs are unique. In your WikiPage model, add the following lines.
Similarly, add the following line to your Product model.
Next we need to change the show views. wiki_column adds a new method to your model called wiki_#{column}. So in your show.rhtml for WikiPage, change:
to
Do the same for Product descriptions so they will link directly to your new wiki.
Lastly, want our url to make sense to users. Our scaffold resource is called WikiPage, because we are adding/editing and viewing individual pages. However, to a user viewing our site, the following url would make more sense.
Thus, the last step is to add a new resource to the routes.rb file
That’s it, you should now have a functioning wiki and your products should integrate with it nicely.
How to use it
Now that your application is wiki enabled, how do you make use of this new found functionality?
You already know you can use the full range of textile commands, they do a better job of explaining their syntax than I could.
What wiki_column adds is the ability to specify wiki words. Those wiki words should be surrounded by square braces. For example, if you wanted to link to a page with the slug ProductionInformation, your code would look like
Conclusion
We designed wiki_column to be easily integrated into new or existing Ruby on Rails applications, as well as to be easy for your customers to use. As alway your comments, critiques, suggestions, and especially patches are welcome. Please post below.