Skip to content

Commit 3cbec7e

Browse files
committed
Forum reply authors are now shown.
1 parent 99f0934 commit 3cbec7e

4 files changed

Lines changed: 21 additions & 5 deletions

File tree

features/forum.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Feature: The Hackety Forum
1818
Then I should see "I need help"
1919
And I should see "I'm here to help!"
2020
Scenario: Make a new reply
21-
Given I'm logged in
21+
Given I'm logged in as "steve"
2222
And there's a discussion named "I need help" in "learning_ruby" with a reply
2323
And I go to the forums
2424
And I follow "Learning Ruby"
@@ -29,6 +29,7 @@ Feature: The Hackety Forum
2929
Then I should be on the discussion "learning_ruby/i_need_help" page
3030
And I should see "Replied!"
3131
And I should see "I'll help you"
32+
And I should see "steve says:"
3233
Scenario: Make a new discussion
3334
Given I'm logged in
3435
And I go to the forums

models/reply.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,18 @@ class Reply
66
#the body of the reply
77
key :body, String
88

9+
#the person who wrote it
10+
key :author, String
11+
12+
#we need to make sure we have an author
13+
validate_on_create :author_check
14+
15+
private
16+
17+
def author_check
18+
if author.nil?
19+
errors.add(:author, "Someone must have written this reply!")
20+
end
21+
end
22+
923
end

views/discussions/show.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
%ul
66
- @discussion.replies.each do |reply|
7-
%li= reply.body
7+
%li #{reply.author} says: #{reply.body}
88

99
%a{ :href => "/forums/reply/to/#{@discussion.forum}/#{@discussion.slug}"} Reply
1010
%a{ :href => "/forums/#{@discussion.forum}" } Back to Discussions

views/forums/reply.haml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
%form{:action => "/forums/reply/to/#{@forum}/#{@discussion}", :method => "POST"}
2-
%label{:for => "reply_body"} Body
3-
%input{:type => "text", :id => "reply_body", :name => "reply[body]"}
4-
%input{:type => "submit", :value => "Create Reply"}
2+
%label{:for => "reply_body"} Body
3+
%input{:type => "text", :id => "reply_body", :name => "reply[body]"}
4+
%input{:type => "hidden", :id => "reply_author", :name => "reply[author]", :value => current_user.username}
5+
%input{:type => "submit", :value => "Create Reply"}

0 commit comments

Comments
 (0)