Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- resources :comments, only: [:create, :update] do
- member do
- post 'flag'
- end
- end
- def update
- @comment = Comment.find(params[:id])
- new_status = @comment.disabled ? false : true
- # binding.pry => I'm not even reaching that method
- if @comment.update(disabled: new_status)
- CommentDisabledMailer.send_comment_disabled_confirmation(@comment).deliver_now
- redirect_to "https://media.giphy.com/media/YfGkjrnVIk3jq/giphy.gif" # a funny gif url
- else
- render json: { errors: @comment.errors.messages }, status: :unprocessable_entity
- end
- end
- def flag
- @comment.update(flagged: @comment.flagged + 1)
- render json: @comment, serializer: Api::V1::CommentSerializer, status: 201, root: nil
- FlagMailer.send_flag_mail(@comment).deliver_now
- end
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- </head>
- <body>
- <!-- some meta data about my comment -->
- <h2> <%= link_to "Disabled this comment", api_v1_comment_url(@comment), method: :put, action: :update %> </h2>
- </body>
- </html>
- <a href="<%= api_v1_comment_url(@comment) %>" data-method="put">Disabled this comment</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement