Class: Admin::PermissionsController

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

Instance Method Summary collapse

Instance Method Details

#createObject



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

def create
  @page = Page.find(params[:page_id])
  scope = @group.permissions.for(@page)
  @permission = scope.first || scope.create!
  respond_to do |format|
    format.html { 
      flash[:notice] = "#{@page.title} bound to group #{@group.name}"
      redirect_to admin_group_url(@group) 
    }
    format.js { render :partial => 'page' }
  end
end

#destroyObject



22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/admin/permissions_controller.rb', line 22

def destroy
  @permission ||= @group.permissions.find(params[:id])
  @page = @permission.permitted
  @permission.delete if @permission
  respond_to do |format|
    format.html { 
      flash[:notice] = "#{@page.title} released from group #{@group.name}"
      redirect_to admin_group_url(@group)
    }
    format.js { render :partial => 'page' }
  end
end

#indexObject



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

def index
  redirect_to admin_group_url(@group)
end

#toggleObject



35
36
37
38
39
40
41
# File 'app/controllers/admin/permissions_controller.rb', line 35

def toggle
  if @permission = @group.permission_for(@page)
    destroy
  else
    create
  end
end