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 2

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
The System Design
Now that you have a fairly good idea of how the UI will look, let's look at the more technical aspects, such as the basic design of the application. Figure 5 shows the design of the RailsWiki application, which uses a typical model-view-controller (MVC) architecture with an atypical persistence solution: a file system. As previously mentioned, I intentionally chose a file-based persistence scheme to keep the Wiki system as simple as possible. After all, as the inventor of Wiki, Ward Cunningham, has himself said about the Wiki concept: "What's the simplest thing that could possibly work?"

Click to enlarge

Figure 5. RailsWiki Design

Coding The Application
Assuming your software is properly installed, you are ready to begin coding using Ruby and Rails.



One of the beautiful things about Rails is that it generates a lot of code, directories, and files in order to give you a jumpstart for developing a new web application. In order to generate files for RailsWiki, the very first command you will type is the rails command from the top-level directory, under which you want your application's parent and sub-directories created (for example, /users/anil/dev/ or c:\anil\dev), as shown here:

> rails railswiki

If the rails command worked properly, you will see a bunch of directories and files created for you. Some of the directories you will work with in this article include the following:

  • app/controllers/
  • app/models/
  • app/views/
  • app/helpers/
  • public/stylesheets/
  • test/unit/
  • config/
  • script/

Author's Note Regarding Relative Command and Directory Path Names: From this point forward, any commands and directories listed will be relative to the top-level directory of the RailsWiki application. For example, app/views/ in my case would be located under c:\anil\dev\railswiki\app\views\.

Generating Controller and View Stub Files
The first few files you will develop (or rather, generate) include the controller and corresponding view files. So start by typing the following command from the top-level directory of your Rails application:

ruby script/generate controller Wiki index view edit print help

The generate command will create several files, some of which include the following:

  • app/controllers/wiki_controller.rb
  • app/views/layouts/application.rhtml
  • app/views/wiki/edit.rhtml
  • app/views/wiki/help.rhtml
  • app/views/wiki/index.rhtml
  • app/views/wiki/print.rhtml
  • app/views/wiki/view.rhtml

At this point, you already have a working web application. To test your stub application, start the bundled WEBrick HTTP server by typing the following command:

ruby script/server

Once the web server start has started, open http://localhost:3000/wiki/ in your web browser and you should see a screen similar to the one shown in Figure 6.

Click to enlarge

Figure 6. Output of Stub index.rhtml

Before adding custom code in the generated controller and view stub files, you will write a model class first to serve as your wiki engine.



Comment and Contribute

 

 

 

 

 


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

 

 

Sitemap