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_code, #changelog_url, #donations_enabled?, #jquery_include_tag, #pod_name, #pod_version, #popover_with_close_html, #qrcode_uri, #service_unconnected?, #source_url, #timeago

Instance Method Details

#createObject


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

def create
  like = like_service.create(params[:post_id])
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid
  render plain: I18n.t("likes.create.error"), status: 422
else
  respond_to do |format|
    format.html { head :created }
    format.mobile { redirect_to post_path(like.post_id) }
    format.json { render json: like.as_api_response(:backbone), status: 201 }
  end
end

#destroyObject


31
32
33
34
35
36
37
# File 'app/controllers/likes_controller.rb', line 31

def destroy
  if like_service.destroy(params[:id])
    head :no_content
  else
    render plain: I18n.t("likes.destroy.error"), status: 404
  end
end

#indexObject


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

def index
  render json: like_service.find_for_post(params[:post_id])
    .includes(author: :profile)
    .as_api_response(:backbone)
end