Class: AspectMembershipsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/aspect_memberships_controller.rb

Overview

Copyright © 2010, 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 inherited from ApplicationController

#after_sign_in_path_for, #clear_gc_stats, #ensure_http_referer_is_set, #ensure_page, #grammatical_gender, #redirect_unless_admin, #set_git_header, #set_grammatical_gender, #set_header_data, #set_invites, #set_locale, #which_action_and_user

Instance Method Details

- (Object) create



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

def create
  @person = Person.find(params[:person_id])
  @aspect = current_user.aspects.where(:id => params[:aspect_id]).first

  if @contact = current_user.(@person, @aspect)

    flash.now[:notice] =  I18n.t 'aspects.add_to_aspect.success'

  else
    flash[:error] = I18n.t 'contacts.create.failure'
    redirect_to :back
  end
end

- (Object) destroy



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/aspect_memberships_controller.rb', line 9

def destroy
  #note :id is garbage

  @person_id = params[:person_id]
  @aspect_id = params[:aspect_id]

  @contact = current_user.contact_for(Person.where(:id => @person_id).first)
  membership = @contact ? @contact.aspect_memberships.where(:aspect_id => @aspect_id).first : nil

  if membership && membership.destroy 
      @aspect = membership.aspect

      flash.now[:notice] = I18n.t 'aspect_memberships.destroy.success'

    else
      flash.now[:error] = I18n.t 'aspect_memberships.destroy.failure'
      errors = membership ? membership.errors.full_messages : t('aspect_memberships.destroy.no_membership')
      respond_to do |format|
        format.js  { render :text => errors, :status => 403 }
        format.html{
          redirect_to :back
        }
    end
  end
end

- (Object) update



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'app/controllers/aspect_memberships_controller.rb', line 49

def update
  @person = Person.find(params[:person_id])
  @from_aspect = current_user.aspects.where(:id => params[:aspect_id]).first
  @to_aspect = current_user.aspects.where(:id => params[:to]).first

  response_hash = { }

  unless current_user.move_contact( @person, @to_aspect, @from_aspect)
    flash[:error] = I18n.t 'aspects.move_contact.error',:inspect => params.inspect
  end
  if aspect = current_user.aspects.where(:id => params[:to]).first
    response_hash[:notice] = I18n.t 'aspects.move_contact.success'
    response_hash[:success] = true
  else
    response_hash[:notice] = I18n.t 'aspects.move_contact.failure'
    response_hash[:success] = false
  end

  render :text => response_hash.to_json
end