Permalink
Browse files

Add destroy action to comments

  • Loading branch information...
1 parent 7ca9dfa commit f41049690b62b0661cb7f47f565a3e3609490039 @anthonylewis anthonylewis committed Mar 14, 2015
Showing with 16 additions and 1 deletion.
  1. +12 −0 app/controllers/comments_controller.rb
  2. +3 −0 app/views/comments/_comment.html.erb
  3. +1 −1 config/routes.rb
@@ -9,6 +9,18 @@ def create
end
end
+ def destroy
+ @post = Post.find(params[:post_id])
+ @comment = @post.comments.find(params[:id])
+
+ if @comment
+ @comment.destroy
+ redirect_to @post, notice: 'Comment was successfully destroyed.'
+ else
+ redirect_to @post, alert: 'Error destroying comment.'
+ end
+ end
+
private
def comment_params
@@ -3,3 +3,6 @@
<blockquote>
<%= comment.body %>
</blockquote>
+
+<%= link_to 'Destroy', post_comment_path(comment.post, comment),
+ method: :delete, data: { confirm: 'Are you sure?' } %>
View
@@ -1,6 +1,6 @@
Rails.application.routes.draw do
resources :posts do
- resources :comments, only: :create
+ resources :comments, only: [:create, :destroy]
end
root 'posts#index'

0 comments on commit f410496

Please sign in to comment.