Sha256: fcb3dcb64e6227dea1d05f74c920cddaf06edee5d5e5f8aa278848035a1f6519

Contents?: true

Size: 1.4 KB

Versions: 5

Compression:

Stored size: 1.4 KB

Contents

module Boxroom
  class GroupsController < Boxroom::ApplicationController
    include Boxroom::BaseController

    before_action :require_admin
    before_action :require_existing_group, :only => [:edit, :update, :destroy]
    before_action :require_group_isnt_admins_group, :only => [:edit, :update, :destroy]

    def index
      @groups = Group.order(:name)
    end

    def new
      @group = Group.new
    end

    def create
      @group = Group.new(permitted_params.group)

      if @group.save
        redirect_to groups_url
      else
        render :action => 'new'
      end
    end

    # Note: @group is set in require_existing_group
    def edit
    end

    # Note: @group is set in require_existing_group
    def update
      if @group.update_attributes(permitted_params.group)
        redirect_to edit_group_url(@group), :notice => t(:your_changes_were_saved)
      else
        render :action => 'edit'
      end
    end

    # Note: @group is set in require_existing_group
    def destroy
      @group.destroy
      redirect_to groups_url
    end

    private

    def require_existing_group
      @group = Group.find(params[:id])
    rescue ActiveRecord::RecordNotFound
      redirect_to groups_url, :alert => t(:group_already_deleted)
    end

    def require_group_isnt_admins_group
      if @group.admins_group?
        redirect_to groups_url, :alert => t(:admins_group_cannot_be_deleted)
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
boxroom-0.0.5 app/controllers/boxroom/groups_controller.rb
boxroom-0.0.4 app/controllers/boxroom/groups_controller.rb
boxroom-0.0.3 app/controllers/boxroom/groups_controller.rb
boxroom-0.0.2 app/controllers/boxroom/groups_controller.rb
boxroom-0.0.1 app/controllers/boxroom/groups_controller.rb