Class: Admin::MembershipsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/admin/memberships_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/admin/memberships_controller.rb', line 9

def create
  @membership = Membership.find_or_create_by_reader_id_and_group_id(@reader.id, @group.id)
  respond_to do |format|
    format.html { 
      flash[:notice] = "#{@reader.preferred_name} added to group #{@group.name}"
      redirect_to admin_group_url(@group) 
    }
    format.js { render :partial => 'reader' }
  end
end

#destroyObject



20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/admin/memberships_controller.rb', line 20

def destroy
  @membership ||= @group.memberships.find(params[:id])
  @reader = @membership.reader
  @membership.delete if @membership
  respond_to do |format|
    format.html { 
      flash[:notice] = "#{@reader.preferred_name} removed from group #{@group.name}" if @membership
      redirect_to admin_group_url(@group) 
    }
    format.js { render :partial => 'reader' }
  end
end

#editObject



41
42
43
44
45
46
# File 'app/controllers/admin/memberships_controller.rb', line 41

def edit
  @membership = @group.memberships.find(params[:id])
  respond_to do |format|
    format.js { render :partial => 'admin/memberships/role_form' }
  end
end

#indexObject



5
6
7
# File 'app/controllers/admin/memberships_controller.rb', line 5

def index
  redirect_to admin_group_url(@group)
end

#toggleObject



33
34
35
36
37
38
39
# File 'app/controllers/admin/memberships_controller.rb', line 33

def toggle
  if @membership = Membership.find_by_reader_id_and_group_id(@reader.id, @group.id)
    destroy
  else
    create
  end
end

#updateObject



48
49
50
51
52
53
54
55
# File 'app/controllers/admin/memberships_controller.rb', line 48

def update
  @membership = @group.memberships.find(params[:id])
  @membership.update_attributes(params[:membership])
  @membership.save!
  respond_to do |format|
    format.js { render :partial => 'admin/memberships/role' }
  end
end