Class: AspectMembershipsController

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


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/aspect_memberships_controller.rb', line 30

def create
  aspect_membership = AspectsMembershipService.new(current_user).create(params[:aspect_id], params[:person_id])

  if aspect_membership
    respond_to do |format|
      format.json do
        render json: AspectMembershipPresenter.new(aspect_membership).base_hash
      end
    end
  else
    respond_to do |format|
      format.json do
        render plain: I18n.t("aspects.add_to_aspect.failure"), status: 409
      end
    end
  end
rescue RuntimeError
  respond_to do |format|
    format.json do
      render plain: I18n.t("aspects.add_to_aspect.failure"), status: :conflict
    end
  end
end

#destroyObject


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

def destroy
  delete_results = AspectsMembershipService.new(current_user).destroy_by_membership_id(params[:id])
  success = delete_results[:success]
  membership = delete_results[:membership]

  # set the flash message
  respond_to do |format|
    format.json do
      if success
        render json: AspectMembershipPresenter.new(membership).base_hash
      else
        render plain: membership.errors.full_messages, status: 403
      end
    end
  end
end