Class: CommentsController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper
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

Methods included from ApplicationHelper

#all_services_connected?, #bookmarklet, #changelog_url, #contacts_link, #jquery_include_tag, #magic_bookmarklet_link, #pod_name, #pod_version, #popover_with_close_html, #raw_bookmarklet, #timeago

Instance Method Details

#createObject


17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/comments_controller.rb', line 17

def create
  post = current_user.find_visible_shareable_by_id(Post, params[:post_id])
  @comment = current_user.comment!(post, params[:text]) if post

  if @comment
    respond_to do |format|
      format.json{ render :json => CommentPresenter.new(@comment), :status => 201 }
      format.html{ render :nothing => true, :status => 201 }
      format.mobile{ render :partial => 'comment', :locals => {:post => @comment.post, :comment => @comment} }
    end
  else
    render :nothing => true, :status => 422
  end
end

#destroyObject


32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/controllers/comments_controller.rb', line 32

def destroy
  @comment = Comment.find(params[:id])
  if current_user.owns?(@comment) || current_user.owns?(@comment.parent)
    current_user.retract(@comment)
    respond_to do |format|
      format.js { render :nothing => true, :status => 204 }
      format.json { render :nothing => true, :status => 204 }
      format.mobile{ redirect_to :back }
    end
  else
    respond_to do |format|
      format.mobile { redirect_to :back }
      format.any(:js, :json) {render :nothing => true, :status => 403}
    end
  end
end

#indexObject

Raises:

  • (ActiveRecord::RecordNotFound)

53
54
55
56
57
58
59
60
61
62
# File 'app/controllers/comments_controller.rb', line 53

def index
  find_post
  raise(ActiveRecord::RecordNotFound.new) unless @post

  @comments = @post.comments.for_a_stream
  respond_with do |format|
    format.json  { render :json => CommentPresenter.as_collection(@comments), :status => 200 }
    format.mobile{render :layout => false}
  end
end

#newObject


49
50
51
# File 'app/controllers/comments_controller.rb', line 49

def new
  render :layout => false
end