In this second part of a four-part series on setting up a forum in Ruby on Rails, you'll learn how to unit test a model, generate a forum controller and view, and more. This article is excerpted from chapter six of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).
Basic Tests for Forum Implementation - Generating the Controller and View (Page 2 of 4 )
George has given us a tight schedule. We could create the forum controller and view files manually, but instead, we decide to save some time and use the generate script. Run the generate script with the following parameters to generate the controller:
$ script/generate controller Forum index reply show post create
Note that each action in the controller maps to a user story:
The index action implements the View Forum user story.
The reply action implements the Reply to Post user story.
The show action implements the View Post user story.
The post and create actions implement the Post to Forum user story.
Open app/controllers/forum_controller.rb in your editor. You should see the following code (note that we have left out part of the file):
class ForumController < ApplicationController
def index end
def reply . . end
Next, we will implement each of the forum user stories.