Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class CommentsController < ApplicationController
- def create
- @post = Post.find(params[:post_id])
- @comment = @post.comments.build(comment_params)
- @comment.user_id = current_user.id if current_user
- if @comment.save
- StatusWorker.perform_aync(@comment.id)
- NotifyChannelsWorker.perform_async(@comment.id)
- AuthorMailer.notify_mail(@post.author.id).deliver_later
- redirect_to post_path(@post)
- else
- render 'new'
- end
- end
- def edit
- @post = Post.find(params[:post_id])
- @comment = @post.comments.find(params[:id])
- end
- def update
- @post = Post.find(params[:post_id])
- @comment = @post.comments.find(params[:id])
- if @comment.update(params[:comment].permit(:comment))
- redirect_to post_path(@post)
- else
- render 'Edit'
- end
- 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(:comment)
- end
- end
Add Comment
Please, Sign In to add comment