Class: Thoth::CommentApiController

Inherits:
Controller
  • Object
show all
Defined in:
lib/thoth/controller/api/comment.rb

Instance Method Summary collapse

Methods inherited from Controller

action_missing

Instance Method Details

#deleteObject

Deletes the specified comment. Returns an HTTP 200 response on success, an HTTP 500 response on failure, or an HTTP 404 response if the specified comment does not exist.

Query Parameters (POST only)

id

comment id

token

form token

Sample Response

Success
{"success":true}
Failure
{"error":"The comment could not be deleted due to a database error."}


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/thoth/controller/api/comment.rb', line 53

def delete
  error_403 unless auth_key_valid? && form_token_valid?
  error_405 unless request.post?
  error_404 unless request[:id] && @comment = Comment[request[:id]]

  response['Content-Type'] = 'application/json'

  @comment.deleted = true

  if @comment.save(:changed => true, :validate => false)
    Ramaze::Cache.action.clear
    Ramaze::Cache.cache_helper_value.clear
    JSON.generate({:success => true})
  else
    respond(JSON.generate({
      :error => 'The comment could not be deleted due to a database error.'
    }, 500))
  end
end