Home arrow Ruby-on-Rails arrow Page 2 - Setting up Posting for a Forum Implementation
RUBY-ON-RAILS

Setting up Posting for a Forum Implementation


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).

Author Info:
By: Apress Publishing
Rating: 5 stars5 stars5 stars5 stars5 stars / 2
May 25, 2010
TABLE OF CONTENTS:
  1. · Setting up Posting for a Forum Implementation
  2. · Implementing the View Post User Story
  3. · Modifying the Controller
  4. · Implementing the Reply to Post User Story

print this article
SEARCH DEVARTICLES

Setting up Posting for a Forum Implementation - Implementing the View Post User Story
(Page 2 of 4 )

On the forum main page, you can see the posts you have created. If you click the post subject, you are taken to a page that displays the text Forum#show. This page was created by the generate script and is clearly not what we want. We need to modify the page so that it shows all the information about the post.

Updating the Integration Test  

Start by modifying the integration test. As we said earlier, most forums have more than one user. We will therefore continue simulating a scenario where Jill is creating a post and George is browsing to the post details page. Add the new view_post method to test/integration/forum_test.rb.

  def view_post(post)
    get "/forum/show/#{post.id}"

    assert_response :success
    assert_template "forum/show"
    assert_tag 'h1', :content => "'#{post.subject}'"
 
end

The new DSL method takes a post object as a parameter, which it uses to access the post details page. On the post details page, the test verifies that the subject of the post can be found in the page content.

Next, we want to simulate George browsing the forum and viewing the post Jill created. Add a call to the view_post action, as follows (highlighted):

  def test_forum
    jill = new_session_as(:jill)
    george = new_session_as(:george)
    post = jill.post_to_forum :post => {
     
:name => 'Bookworm',
      :subject => 'Downtime',
      :body => 'Emporium is down again!'
    }
    george.view_forum
    jill.view_forum

    george.view_post post
 
end

Running the test now would cause the test to fail miserably with the following error:

--------------------------------------------
expected tag, but no tag found matching {:tag=>"h1", :content=>"'Downtime'"} in:
--------------------------------------------

This is because you have not yet modified the show action and view to show the details of the post. Remember that we created these earlier with the help of the generate script.


blog comments powered by Disqus
RUBY-ON-RAILS ARTICLES

- Ruby-on-Rails Faces Second Security Flaw in ...
- Ruby 2.0 Prepped for February 2013 Release
- Why LinkedIn Switched from Ruby on Rails
- 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

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




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