mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
23 lines
542 B
Ruby
23 lines
542 B
Ruby
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
|