Skip to content

Commit e0d1eb1

Browse files
committed
Holy forum discussions, batman!
Each forum now has discussions.
1 parent 73d2df8 commit e0d1eb1

7 files changed

Lines changed: 54 additions & 3 deletions

File tree

controllers/forums.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,13 @@
44
#render that template!
55
haml :"forums/index"
66
end
7+
8+
#you can view an individual forum here!
9+
get "/forums/:forum" do
10+
11+
#gotta find all the discussions in this forum
12+
@discussions = Discussion.all(:forum => params[:forum])
13+
14+
#render the template!
15+
haml :"forums/show"
16+
end

factories/discussion.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Factory.define :discussion do |t|
2+
3+
end

features/forum.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,9 @@ Feature: The Hackety Forum
55
Then I should see "Learning Ruby"
66
And I should see "Hackety Help"
77
And I should see "Clubhouse"
8+
Scenario: View discussions in a forum
9+
Given I'm logged in
10+
And there's a discussion named "I need help!" in "learning_ruby"
11+
When I go to the forums
12+
And I follow "Learning Ruby"
13+
Then I should see "I need help!"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Given /^there's a discussion named "([^"]*)" in "([^"]*)"$/ do |title, forum|
2+
Factory(:discussion, :title => title, :forum => forum)
3+
end

models/discussion.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#this model represents a single discussion in the forum
2+
class Discussion
3+
#we need to keep discussions in the database!
4+
include MongoMapper::Document
5+
6+
#the title of a discussion
7+
key :title, String
8+
9+
#this is the forum that it's in.
10+
key :forum, String
11+
12+
#this is the slug for the url
13+
key :slug, String
14+
15+
before_save :make_slug
16+
17+
private
18+
def make_slug
19+
self.slug = self.title.to_slug
20+
end
21+
22+
end

views/forums/index.haml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
%ul
2-
%li Learning Ruby
3-
%li Hackety Help
4-
%li Clubhouse
2+
%li
3+
%a{ :href => "/forums/learning_ruby" } Learning Ruby
4+
%li
5+
%a{ :href => "/forums/hackety_help" } Hackety Help
6+
%li
7+
%a{ :href => "/forums/clubhouse" } Clubhouse

views/forums/show.haml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
%ul
2+
- @discussions.each do |discussion|
3+
%li
4+
%a{ :href => "/forums/#{discussion.forum}/#{discussion.slug}" }= discussion.title

0 commit comments

Comments
 (0)