aboutsummaryrefslogblamecommitdiffstats
path: root/guides/code/getting_started/app/controllers/comments_controller.rb
blob: b2d9bcdf7f78a6325f07bdc6e56e1650b55f7b27 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                
 

                                                                              

                                       
                                                    

                                
 





                                               





                                                        
   
class CommentsController < ApplicationController

  http_basic_authenticate_with name: "dhh", password: "secret", only: :destroy

  def create
    @post = Post.find(params[:post_id])
    @comment = @post.comments.create(comment_params)
    redirect_to post_path(@post)
  end

  def destroy
    @post = Post.find(params[:post_id])
    @comment = @post.comments.find(params[:id])
    @comment.destroy
    redirect_to post_path(@post)
  end

  private

    def comment_params
      params.require(:comment).permit(:commenter, :body)
    end
end