Class: CommentsController

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

Overview

Copyright © 2010-2011, Diaspora Inc. This file is

licensed under the Affero General Public License version 3 or later.  See
the COPYRIGHT file.

Instance Method Summary collapse

Instance Method Details

#createObject


20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/comments_controller.rb', line 20

def create
  begin
    comment = comment_service.create(params[:post_id], params[:text])
  rescue ActiveRecord::RecordNotFound
    render plain: I18n.t("comments.create.error"), status: 404
    return
  end

  if comment
    respond_create_success(comment)
  else
    render plain: I18n.t("comments.create.error"), status: 422
  end
end

#destroyObject


35
36
37
38
39
40
41
# File 'app/controllers/comments_controller.rb', line 35

def destroy
  if comment_service.destroy(params[:id])
    respond_destroy_success
  else
    respond_destroy_error
  end
end

#indexObject


49
50
51
52
53
54
55
# File 'app/controllers/comments_controller.rb', line 49

def index
  comments = comment_service.find_for_post(params[:post_id])
  respond_with do |format|
    format.json { render json: CommentPresenter.as_collection(comments), status: 200 }
    format.mobile { render layout: false, locals: {comments: comments} }
  end
end

#newObject


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

def new
  respond_to do |format|
    format.mobile { render layout: false }
  end
end