Home arrow Ruby-on-Rails arrow Page 2 - Error Checking and Debugging with Ruby on Rails
RUBY-ON-RAILS

Error Checking and Debugging with Ruby on Rails


In this conclusion to a six-part series covering web development and Ruby on Rails, you'll learn how to send error messages to your email and more. This article is excerpted from chapter 15 of the Ruby Cookbook, written by Lucas Carlson and Leonard Richardson (O'Reilly, 2006; ISBN: 0596523696). Copyright © 2006 O'Reilly Media, Inc. All rights reserved. Used with permission from the publisher. Available from booksellers or direct from O'Reilly Media.

Author Info:
By: O'Reilly Media
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
April 26, 2007
TABLE OF CONTENTS:
  1. · Error Checking and Debugging with Ruby on Rails
  2. · 15.21 Documenting Your Web Site
  3. · 15.22 Unit Testing Your Web Site
  4. · 15.23 Using breakpoint in Your Web Application

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Error Checking and Debugging with Ruby on Rails - 15.21 Documenting Your Web Site
(Page 2 of 4 )

Problem

You want to document the controllers, models, and helpers of your web application so that the developers responsible for maintaining the application can understand how it works.

Solution

As with any other Ruby program, you document a Rails application by adding specially-formatted commands to your code. Here's how to add documentation to the FooController class and one of its methods:

  # The FooController controller contains miscellaneous functionality
  # rejected from other controllers.
  class FooController < ApplicationController
   
# The set_random action sets the @random_number instance variable
    # to a random number.
    def set_random
     
@random_number = rand*rand
    end
  end

The documentation for classes and methods goes before their declaration, not after.

When you've finished adding documentation comments to your application, go to your Rails application's root directory and issue the rake appdoc command:

  $ rake appdoc

This Rake task runs RDoc for your Rails application and generates a directory called doc/app. This directory contains a web site with the aggregate of all your documentation comments, cross-referenced against the source code. Open the doc/app/index.rhtml file in any web browser, and you can browse the generated documentation.

Discussion

Your RDoc comments can contain markup and special directives: you can describe your arguments in definition lists, and hide a class or method from documentation with the :nodoc: directive. This is covered in Recipe 17.11.

The only difference between Rails applications and other Ruby programs is that Rails comes with a Rakefile that defines an appdoc task. You don't have to find or write one yourself.

You probably already put inline comments inside your methods, describing the action as it happens. Since the RDoc documentation contains a formatted version of the original source code, these comments will be visible to people going through the RDoc. These comments are formatted as Ruby source code, though, not as RDoc markup.

See Also

  1. Recipe 17.11, "Documenting Your Application"
  2. Chapter 19, especially Recipe 19.2, "Automatically Generating Documentation"
  3. The RDoc for RDoc (http://rdoc.sourceforge.net/doc/index.html)


blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- Adding Style with Action Pack
- Handling HTML in Templates with Action Pack
- Filters, Controllers and Helpers in Action P...
- Action Pack and Controller Filters
- Action Pack Categories and Events
- Logging Out, Events and Templates with Actio...
- Action Pack Sessions and Architecture
- More on Action Pack Partial Templates
- Action Pack Partial Templates
- Displaying Error Messages with the Action Pa...
- Action Pack Request Parameters
- Creating an Action Pack Registration Form
- Ruby on Rails Templates and Layouts
- Action Pack Controller Creation
- Writing an Action Pack Controller

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 1 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials