home about

Instantly add wiki functionality to your Rails app

October 7th, 2007 cpetersen

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:
sudo gem install RedCloth
Next install the wiki_column plugin.
./script/plugin install http://wiki-column.googlecode.com/svn/trunk/wiki_column
Next generate your WikiPage model and your Product model.
./script/generate scaffold_resource WikiPage slug:string body:text created_at:datetime updated_at:datetime
./script/generate scaffold_resource Product name:string description:text price:decimal created_at:datetime updated_at:datetime
Don't forget to migrate.
rake db: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.
1
2
validates_uniqueness_of :slug
wiki_column :body
Similarly, add the following line to your Product model.

wiki_column :description
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:

<%=h @wiki_page.body %>
to

<%= @wiki_page.wiki_body %>
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.
http://company.com/wiki/1
Thus, the last step is to add a new resource to the routes.rb file

map.resources :wiki, :controller => 'wiki_pages'
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
[ProductInformation]

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.

9 Responses to “Instantly add wiki functionality to your Rails app”

  1. roScripts &#45; Webmaster resources and websites Says:
    assay depot: development blog » Blog Archive » Instantly add wiki functionality to your Ra... assay depot: development blog » Blog Archive » Instantly add wiki functionality to your Rails app...
  2. Patrick Crowley Says:
    Nice job, guys. What are the chances for Markdown support being added?
  3. Christopher L Petersen Says:
    Patrick, That is a great idea and something we have discussed. Right now we are a Textile shop (mostly for the table support), so it's not mission critical to add at this point... that being said, I would like to add that in the near future. Maybe one of these weekends I'll knock it out. Thanks! Chris
  4. links for 2007-11-30 Says:
    [...] assay depot: development blog » Blog Archive » Instantly add wiki functionality to your Rails app (tags: plugin rails wiki) [...]
  5. Antonio Says:
    Hi, it's great plugin. But, how can I do nested with other model? I want this: /project/:project_id/wiki/:wiki_page_id It's posible?
  6. lemony snickets a series of unfortunate events movie sequel Says:
    movie reviews failure to launch movie reviews failure to launch [link=http://edukasimedia.com/uploads/thumbs/comment-409.html]movie reviews failure to launch[/link] atlanta georgia in movie theater atlanta georgia in movie theater [link=http://naturcadiz.es/borrar/uploads/thumbs/510.htm]atlanta georgia in movie theater[/link] lemony snickets a series of unfortunate events movie sequel lemony snickets a series of unfortunate events movie sequel [link=http://kerin444.net/expat/uploadfiles/images/topic-1885.htm]lemony snickets a series of unfortunate events movie sequel[/link]
  7. lacey duvalle video clip Says:
    lacey duvalle video clip lacey duvalle video clip [link=http://creative-ad.com/promotion/promo/g2data/data/bugfilasi.html]lacey duvalle video clip[/li.by/classes/editor/uploads/media/news-1728-2008-06-17.html]key bank online[/link]
  8. ryk neethling Says:
    causes for low testosterone causes for low testosterone [link=http://www.technogistics.co.za/rttimport/files/nopasfev.html]causes for low testosterone[/link] audio receiver transmitter video audio receiver transmitter video [link=http://kineticedgeperformance.com/uploadedfiles/testimonials/pics/topic765.htm]audio receiver transmitter video[/link] ryk neethling ryk neethling [link=http://kineticedgeperformance.com/uploadedfiles/testimonials/pics/topic988.htm]ryk neethling[/link]
  9. home Says:
    link http [link=http://lindbrookstargazer.ca/test_phpwebsite/images/pics/sitemap.htm]www[/link] sites home [link=http://escribeaqui.com/templates/eaqgris/styles/sitemap.htm]website[/link] home site [link=http://qomnews.com/date/scripts/index.html]page[/link]

Leave a Reply