Class: LikesController

Inherits:
ApplicationController show all
Includes:
ApplicationHelper
Defined in:
app/controllers/likes_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


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/likes_controller.rb', line 13

def create
  @like = current_user.like!(target) if target rescue ActiveRecord::RecordInvalid

  if @like
    respond_to do |format|
      format.html { render :nothing => true, :status => 201 }
      format.mobile { redirect_to post_path(@like.post_id) }
      format.json { render :json => @like.as_api_response(:backbone), :status => 201 }
    end
  else
    render :nothing => true, :status => 422
  end
end

#destroyObject


27
28
29
30
31
32
33
34
# File 'app/controllers/likes_controller.rb', line 27

def destroy
  @like = Like.find_by_id_and_author_id!(params[:id], current_user.person.id)

  current_user.retract(@like)
  respond_to do |format|
    format.json { render :nothing => true, :status => 204 }
  end
end

#indexObject

I can go when the old stream goes.


37
38
39
40
41
42
43
44
45
# File 'app/controllers/likes_controller.rb', line 37

def index
  @likes = target.likes.includes(:author => :profile)
  @people = @likes.map(&:author)

  respond_to do |format|
    format.all { render :layout => false }
    format.json { render :json => @likes.as_api_response(:backbone) }
  end
end