-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ceae597
commit a7d83b3
Showing
4 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class CommentsController < ApplicationController | ||
def index | ||
@comments = Comment.all | ||
end | ||
|
||
def create | ||
post = Post.find(params[:post_id]) | ||
@comment = post.comments.build(comment_params) | ||
|
||
if @comment.save | ||
redirect_to post, notice: 'Comment has been successfully created.' | ||
else | ||
redirect_to post, alert: 'Hoge!' | ||
end | ||
end | ||
|
||
private | ||
|
||
def comment_params | ||
params.require(:comment).permit(:body).merge(commented_by: current_user) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ def index | |
end | ||
|
||
def show | ||
@comment = @post.comments.new | ||
@comments = @post.comments | ||
end | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters