Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

comment controller should also redirected to board prefixed url.

  • Loading branch information...
commit 83636ade2c8cf4a92ddd2bb6c6893ef5ab2e3475 1 parent c02c40f
@ruseel authored
View
16 app/controllers/comments_controller.rb
@@ -1,23 +1,25 @@
# vim: set fileencoding=utf-8 :
class CommentsController < ApplicationController
- # def index
- # @comments = Comment.all
- # end
+
+ before_filter :set_board
+
+ def set_board
+ @board = Board.where(id: params[:board_id]).first
+ end
+
def show
@comment = Comment.find(params[:id])
end
- # def new
- # end
-
def create
@topic = Topic.find(params[:topic_id])
+ @board = @topic.board
@comment = Comment.new(params[:comment])
@comment.topic = @topic
if @topic && @comment.save
- redirect_to [@board, @topic]
+ redirect_to [@topic.board, @topic]
else
flash[:notice] = "empty body"
@comments = @topic.comments
View
2  app/controllers/topics_controller.rb
@@ -7,6 +7,7 @@ def set_board
@board = Board.where(id: params[:board_id]).first
end
+
def index
@topics = @board.topics.page(params[:page])
end
@@ -23,6 +24,7 @@ def new
def create
@topic = Topic.new(params[:topic])
+ @topic.board = @board
if params[:parent_id].present?
@topic.parent = Topic.find(params[:parent_id])
end
View
2  app/views/topics/_form.html.erb
@@ -1,4 +1,4 @@
-<%= form_for @topic do |f| %>
+<%= form_for [@board,@topic] do |f| %>
<% if @topic.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@topic.errors.count, "error") %> prohibited this topic from being saved:</h2>
View
2  app/views/topics/index.html.erb
@@ -10,7 +10,7 @@
<% @topics.each do |topic| %>
<tr>
<td>
- <%= link_to (depth_mark(topic.depth) + topic.subject), topic %>
+ <%= link_to (depth_mark(topic.depth) + topic.subject), [topic.board,topic] %>
</td>
<td><%= topic.created_at %></td>
<td>
View
4 app/views/topics/show.html.erb
@@ -8,8 +8,8 @@
</div>
<div class="actions">
- <%= link_to "답글", new_topic_path(parent_id: @topic.id) %>
- <%= link_to "목록", topics_path %>
+ <%= link_to "답글", new_board_topic_path(@board, parent_id: @topic.id) %>
+ <%= link_to "목록", board_topics_path(@board) %>
</div>
View
1  test/fixtures/topics.yml
@@ -3,6 +3,7 @@
one:
subject: fixture_one
body: body of one
+ board: one
topic_belongs_to_board_two:
subject: topic_belongs_to_board_two
View
3  test/functional/comments_controller_test.rb
@@ -2,6 +2,7 @@
class CommentsControllerTest < ActionController::TestCase
setup do
+ @board = boards(:one)
@comment = comments(:one)
@topic = topics(:one)
end
@@ -17,7 +18,7 @@ class CommentsControllerTest < ActionController::TestCase
post :create, comment: { body: "comment" }, topic_id: @topic
end
- assert_redirected_to @topic
+ assert_redirected_to [@topic.board, @topic]
end
test "should show flash for empty body" do
View
1  test/functional/topics_controller_test.rb
@@ -59,6 +59,7 @@ class TopicsControllerTest < ActionController::TestCase
test "should create reply" do
reply = topics(:reply)
post :create, topic: { subject: reply.subject, body: reply.body }, parent_id: @topic, board_id: @board
+ assert_equal @board, assigns(:topic).board
assert_equal @topic.boardish.inc_at_depth(1), assigns(:topic).boardish
end
end
View
2  test/integration/board_flow_test.rb
@@ -7,6 +7,6 @@ class BoardFlowTest < ActionDispatch::IntegrationTest
test "get url topics of boards(:one) " do
get board_topics_path(boards(:one))
- assert_equal 0, assigns(:topics).size
+ assert_equal 1, assigns(:topics).size
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.