Class: AspectsController

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


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

def create
  @aspect = current_user.aspects.build(aspect_params)
  aspecting_person_id = params[:person_id]

  if @aspect.save
    result = {id: @aspect.id, name: @aspect.name}
    if aspecting_person_id.present?
      aspect_membership = connect_person_to_aspect(aspecting_person_id)
      result[:aspect_membership] = AspectMembershipPresenter.new(aspect_membership).base_hash if aspect_membership
    end

    render json: result
  else
    head :unprocessable_entity
  end
end

#destroyObject


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

def destroy
  begin
    if current_user.auto_follow_back && aspect.id == current_user.auto_follow_back_aspect.id
      current_user.update(auto_follow_back: false, auto_follow_back_aspect: nil)
      flash[:notice] = I18n.t "aspects.destroy.success_auto_follow_back", name: aspect.name
    else
      flash[:notice] = I18n.t "aspects.destroy.success", name: aspect.name
    end
    aspect.destroy
  rescue ActiveRecord::StatementInvalid => e
    flash[:error] = I18n.t "aspects.destroy.failure", name: aspect.name
  end

  if request.referer.include?("contacts")
    redirect_to contacts_path
  else
    redirect_to aspects_path
  end
end

#showObject


51
52
53
54
55
56
57
# File 'app/controllers/aspects_controller.rb', line 51

def show
  if aspect
    redirect_to aspects_path("a_ids[]" => aspect.id)
  else
    redirect_to aspects_path
  end
end

#updateObject


59
60
61
62
63
64
65
66
# File 'app/controllers/aspects_controller.rb', line 59

def update
  if aspect.update!(aspect_params)
    flash[:notice] = I18n.t "aspects.update.success", name: aspect.name
  else
    flash[:error] = I18n.t "aspects.update.failure", name: aspect.name
  end
  render json: {id: aspect.id, name: aspect.name}
end

#update_orderObject


68
69
70
71
72
73
# File 'app/controllers/aspects_controller.rb', line 68

def update_order
  params[:ordered_aspect_ids].each_with_index do |id, i|
    current_user.aspects.find(id).update(order_id: i)
  end
  head :no_content
end