Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Build a Wiki System with Rails : Page 5

Learn how to build a simple, file-based Wiki system using the Ruby on Rails web application framework. You won't believe how easy it is.


advertisement
Other Notable Files
The app/views/layouts/application.rhtml-generated file provides an application-wide (that is, across all controllers), consistent look-and-feel, which includes things such as the header and footer. However, you can also have controller-specific layouts, so I renamed this file to wiki.rhtml to make it applicable only to your WikiController. This wiki.rhtml file also links to the cascading style sheet (CSS) file, public/stylesheets/wiki.css, which you can in turn use to control the aesthetics of your application such as the colors, fonts, and so on.

The one other pre-generated file, which I have tweaked slightly, is config/routes.rb. By modifying one of the mappings and deleting the generated public/index.html file, you can access the index page without the trailing URI (that is, /wiki/):

map.connect '', :controller => "wiki"



In other words, a URL of http://localhost:3000/ is treated the same as http://localhost:3000/wiki/.

I also added the following line to the config/routes.rb file to allow you to use clean REST (Representational State Transfer)-like web services URLs:

map.connect 'wiki/:action/:f', :controller => "wiki"

For example, with the above line added, a URL such as http://localhost:3000/wiki/view?f=untitled would look like http://localhost:3000/wiki/view/untitled. This sort of URL formatting is something the Rails helper methods (such as link_to, redirect_to, url_for, and others) automatically handle for you.

What Next?
You have successfully built a completely functional Wiki system, but you obviously can add to and enhance this basic system. If you are interested in learning more Rails or simply building upon the downloadable application, here are a couple of suggestions:

  1. Leverage the strengths of Rails and have your application persist its Wiki pages in a database (perhaps using a text data type for the actual Wiki text).
  2. Add search capabilities to the application using an existing Ruby gem that provides indexing and searching capabilities. For example, one such gem named Ferret can be found at ferret.davebalmain.com/trac.
  3. Add support for commonly found Wiki features such as WikiWord, change history, and so on.

Apart from that, have fun coding with Ruby and Rails!



Anil Hemrajani has developed code for 20 years, published dozens of articles and a popular book, won multiple industry awards, given talks in four continents, built a popular award-winning developer community, and run a successful company. He is currently an independent consultant.
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap