Guest User

comments.controller

a guest
Aug 26th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 0.60 KB | None | 0 0
  1. class CommentsController < ApplicationController
  2.     http_basic_authenticate_with name: "Donaukinder", password: "123", only: [:destroy]
  3.  
  4.     def create
  5.         @post = Post.find(params[:post_id])
  6.         @comment = @post.comments.create(comment_params)
  7.         redirect_to post_path(@post)
  8.     end
  9.  
  10.     def destroy
  11.         @post = Post.find(params[:post_id])
  12.         @comment = @post.comments.find(params[:id])
  13.         @comment.destroy
  14.         redirect_to post_path(@post)
  15.     end
  16.    
  17.    
  18.     private def comment_params
  19.         params.require(:comment).permit(:username, :body)
  20.     end
  21. end
Add Comment
Please, Sign In to add comment