Class: Proclaim::CommentsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/proclaim/comments_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



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
# File 'app/controllers/proclaim/comments_controller.rb', line 9

def create
  @comment = Comment.new(comment_params)

  errors = Array.new
  options = Hash.new
  options[:success_json] = lambda {comment_json(@comment)}
  options[:failure_json] = lambda {errors}
  options[:operation] = lambda do
    if @comment.save
      return true
    else
      errors += @comment.errors.full_messages
      return false
    end
  end

  # Don't leak that the post actually exists. Turn the "unauthorized"
  # into a "not found"
  options[:unauthorized_status] = :not_found

  handleJsonRequest(@comment, options) do
    if antispam_params[:answer] != antispam_params[:solution]
      respond_to do |format|
        format.json { render json: ["Antispam question wasn't answered correctly"], status: :unprocessable_entity }
      end
    end
  end
end

#destroyObject



44
45
46
47
48
# File 'app/controllers/proclaim/comments_controller.rb', line 44

def destroy
  handleJsonRequest(@comment) do
    @comment.destroy
  end
end

#updateObject



38
39
40
41
42
# File 'app/controllers/proclaim/comments_controller.rb', line 38

def update
  handleJsonRequest(@comment,
                    operation: lambda {@comment.update(comment_params)},
                    success_json: lambda {comment_json(@comment)})
end