Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. resources :comments, only: [:create, :update] do
  2. member do
  3. post 'flag'
  4. end
  5. end
  6.  
  7. def update
  8. @comment = Comment.find(params[:id])
  9. new_status = @comment.disabled ? false : true
  10.  
  11. # binding.pry => I'm not even reaching that method
  12.  
  13. if @comment.update(disabled: new_status)
  14. CommentDisabledMailer.send_comment_disabled_confirmation(@comment).deliver_now
  15. redirect_to "https://media.giphy.com/media/YfGkjrnVIk3jq/giphy.gif" # a funny gif url
  16. else
  17. render json: { errors: @comment.errors.messages }, status: :unprocessable_entity
  18. end
  19. end
  20.  
  21. def flag
  22. @comment.update(flagged: @comment.flagged + 1)
  23. render json: @comment, serializer: Api::V1::CommentSerializer, status: 201, root: nil
  24. FlagMailer.send_flag_mail(@comment).deliver_now
  25. end
  26.  
  27. <!DOCTYPE html>
  28. <html>
  29. <head>
  30. <meta charset="utf-8">
  31. </head>
  32. <body>
  33. <!-- some meta data about my comment -->
  34.  
  35. <h2> <%= link_to "Disabled this comment", api_v1_comment_url(@comment), method: :put, action: :update %> </h2>
  36.  
  37. </body>
  38. </html>
  39.  
  40. <a href="<%= api_v1_comment_url(@comment) %>" data-method="put">Disabled this comment</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement