In this conclusion to a four-part series on implementing a forum with Ruby on Rails, we'll finish setting up the part of the forum that allows users to view entries, and add the sections that let them make and reply to posts. This article is excerpted from chapter six of the book Practical Rails Projects, written by Eldon Alameda (Apress; ISBN: 1590597818).
Note It is extremely important that you escape all data that is entered by users with the h method. This helps in protecting you from security risks, such as cross-site scripting attacks. For more information about how to protect your site against various attacks, refer to Chapter 8, Security.
With the action and view in place, the integration test should now work, so run it once more to verify that the integration test passes:
$ ruby test/integration/forum_test.rb
-------------------------------------------- Loaded suite test/integration/forum_test Started . Finished in 0.145623 seconds.
You should also perform a manual test to verify that the page works correctly. Open http://localhost:3000/forum/show/1 (you might have to change the id), and you should see the details of the post, as shown in Figure 6-5. Notice that there is a Reply link at the bottom of the page.
Figure 6-5.The final version of the post page
The Reply to Post user story is the last user story that we need to implement.
In case you want to display links to replies (to the current post) on the Show Post page, you can add the following code to the view:
<%= display_as_threads @post.direct_children%>
This displays the replies to the current post, but only the direct replies. To display all replies use the following code: