Skip to content

Commit db5acd0

Browse files
committed
Blog Completed
1 parent df5fcca commit db5acd0

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

app/controllers/comments_controller.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ class CommentsController < ApplicationController
22

33
def create
44
@post = Post.find(params[:post_id])
5-
@comment = @post.comments.create(params[:comment]).permit(:name, :comment))
6-
redirect_to post_path(@path)
5+
@comment = @post.comments.create(params[:comment].permit(:name, :comment))
6+
redirect_to post_path(@post)
77
end
88

99
def destroy
10+
@post = Post.find(params[:post_id])
11+
@comment = @post.comments.find(params[:id])
12+
@comment.destroy
13+
redirect_to post_path(@post)
1014
end
1115

1216
end

app/views/comments/_comment.html.erb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<div class="box">
2+
<article class="media">
3+
<div class="media-content">
4+
<div class="content">
5+
<p>
6+
<strong><%= comment.name %>: </strog>
7+
<%= comment.comment %>
8+
</p>
9+
</div>
10+
</div>
11+
<%= link_to 'Delete', [comment.post, comment], method: :delete, class: "button is-danger", data: { confirm: "Are you Sure?" } %>
12+
</article>
13+
</div>

app/views/posts/show.html.erb

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

2727
<section class="section comments">
2828
<div class="container">
29-
<h2 class="subtitle is-5"><strong><%= posts.comments.count %></strong> Comments</h2>
29+
<h2 class="subtitle is-5"><strong><%= @post.comments.count %></strong> Comments</h2>
3030
<%= render @post.comments %>
3131

3232
<div class="comment-form">

config/routes.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Rails.application.routes.draw do
22
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
3-
resources :posts
3+
resources :posts do
4+
resources :comments
5+
end
46
root "posts#index"
57
end

0 commit comments

Comments
 (0)