Guest User

Untitled

a guest
Oct 30th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. class CommentsController < ApplicationController
  2. def create
  3. @post = Post.find(params[:post_id])
  4. @comment = @post.comments.build(comment_params)
  5. @comment.user_id = current_user.id if current_user
  6.  
  7. if @comment.save
  8. StatusWorker.perform_aync(@comment.id)
  9. NotifyChannelsWorker.perform_async(@comment.id)
  10. AuthorMailer.notify_mail(@post.author.id).deliver_later
  11. redirect_to post_path(@post)
  12. else
  13. render 'new'
  14. end
  15. end
  16.  
  17. def edit
  18. @post = Post.find(params[:post_id])
  19. @comment = @post.comments.find(params[:id])
  20. end
  21.  
  22. def update
  23. @post = Post.find(params[:post_id])
  24. @comment = @post.comments.find(params[:id])
  25.  
  26. if @comment.update(params[:comment].permit(:comment))
  27. redirect_to post_path(@post)
  28. else
  29. render 'Edit'
  30. end
  31. end
  32.  
  33. def destroy
  34. @post = Post.find(params[:post_id])
  35. @comment = @post.comments.find(params[:id])
  36. @comment.destroy
  37. redirect_to post_path(@post)
  38. end
  39.  
  40. private
  41.  
  42. def comment_params
  43. params.require(:comment).permit(:comment)
  44. end
  45. end
Add Comment
Please, Sign In to add comment