Class: Proclaim::CommentsController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Proclaim::CommentsController
- Defined in:
- app/controllers/proclaim/comments_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'app/controllers/proclaim/comments_controller.rb', line 9 def create @comment = Comment.new(comment_params) begin @comment if antispam_params[:answer] == antispam_params[:solution] subscription = nil params = subscription_params if params and params[:subscribe] subscription = Subscription.new(email: params[:email], post: @comment.post) end respond_to do |format| begin Comment.transaction do @comment.save! if subscription subscription.save! end format.json { render_comment_json(@comment) } end rescue ActiveRecord::RecordInvalid errorMessages = Array.new errorMessages += @comment.errors. if subscription errorMessages += subscription.errors. end format.json { render json: errorMessages, status: :unprocessable_entity } end end else respond_to do |format| format.json { render json: ["Antispam question wasn't answered correctly"], status: :unprocessable_entity } end end rescue Pundit::NotAuthorizedError respond_to do |format| # Don't leak that the post actually exists. Turn the # "unauthorized" into a "not found" format.json { render json: true, status: :not_found } end end end |
#destroy ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/proclaim/comments_controller.rb', line 76 def destroy begin @comment respond_to do |format| @comment.destroy format.json { render json: true, status: :ok } end rescue Pundit::NotAuthorizedError respond_to do |format| format.json { render json: true, status: :unauthorized } end end end |
#update ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/proclaim/comments_controller.rb', line 58 def update begin @comment respond_to do |format| if @comment.update(comment_params) format.json { render_comment_json(@comment) } else format.json { render json: @comment.errors., status: :unprocessable_entity } end end rescue Pundit::NotAuthorizedError respond_to do |format| format.json { render json: true, status: :unauthorized } end end end |