class Rbac::GroupsController

Public Instance Methods

create() click to toggle source

POST /groups POST /groups.json

# File lib/generators/rbac/create/templates/controllers/rbac/groups_controller.rb, line 30
def create
  @group = Rbac::Group.new(group_params)

  respond_to do |format|
    if @group.save
      @group.privileges = Rbac::Privilege.where(id: params[:privilege_ids])
      format.html { redirect_to rbac_groups_path, notice: 'Group was successfully created.' }
      format.json { render :show, status: :created, location: @group }
    else
      format.html { redirect_to new_rbac_group_path }
      format.json { render json: @group.errors, status: :unprocessable_entity }
    end
  end
end
destroy() click to toggle source

DELETE /groups/1 DELETE /groups/1.json

# File lib/generators/rbac/create/templates/controllers/rbac/groups_controller.rb, line 62
def destroy
  @group.destroy
  respond_to do |format|
    format.html { redirect_to rbac_groups_url, notice: 'Group was successfully destroyed.' }
    format.json { head :no_content }
  end
end
edit() click to toggle source

GET /groups/1/edit

# File lib/generators/rbac/create/templates/controllers/rbac/groups_controller.rb, line 23
def edit
  @group_privileges = @group.privileges
  @privileges = Rbac::Privilege.all
end
index() click to toggle source

GET /groups GET /groups.json

# File lib/generators/rbac/create/templates/controllers/rbac/groups_controller.rb, line 7
def index
  @groups = Rbac::Group.all
end
new() click to toggle source

GET /groups/new

# File lib/generators/rbac/create/templates/controllers/rbac/groups_controller.rb, line 17
def new
  @group = Rbac::Group.new
  @privileges = Rbac::Privilege.all
end
show() click to toggle source

GET /groups/1 GET /groups/1.json

# File lib/generators/rbac/create/templates/controllers/rbac/groups_controller.rb, line 13
def show
end
update() click to toggle source

PATCH/PUT /groups/1 PATCH/PUT /groups/1.json

# File lib/generators/rbac/create/templates/controllers/rbac/groups_controller.rb, line 47
def update
  respond_to do |format|
    if @group.update(group_params)
      @group.privileges = Rbac::Privilege.where(id: params[:privilege_ids])
      format.html { redirect_to rbac_groups_path, notice: 'Group was successfully updated.' }
      format.json { render :show, status: :ok, location: @group }
    else
      format.html { redirect_to edit_rbac_group_path }
      format.json { render json: @group.errors, status: :unprocessable_entity }
    end
  end
end

Private Instance Methods

group_params() click to toggle source

Never trust parameters from the scary internet, only allow the white list through.

# File lib/generators/rbac/create/templates/controllers/rbac/groups_controller.rb, line 77
def group_params
  params.require(:rbac_group).permit(:name, :description, :privilege_ids, :is_active)
end
set_group() click to toggle source

Use callbacks to share common setup or constraints between actions.

# File lib/generators/rbac/create/templates/controllers/rbac/groups_controller.rb, line 72
def set_group
  @group = Rbac::Group.find(params[:id])
end