Sha256: a0c7fa1f4175f4c310b6b5d379c9f04d4f51edc95b55f166173bc8d5cdcac634

Contents?: true

Size: 1.61 KB

Versions: 8

Compression:

Stored size: 1.61 KB

Contents

require_dependency 'guts/application_controller'

module Guts
  # Groups controller
  class GroupsController < ApplicationController
    before_action :set_group, only: [:show, :edit, :update, :destroy]

    # Displays a list of groups
    def index
      @groups = Group.all
    end
    
    # Shows details about a single group
    def show
    end

    # Creation of a new group
    def new
      @group = Group.new
    end

    # Editing for a group
    def edit
    end

    # Creates a group through post
    # @note Redirects to #index if successfull or re-renders #new if not
    def create
      @group = Group.new group_params

      if @group.save
        flash[:notice] = 'Group was successfully created.'
        redirect_to groups_path
      else
        render :new
      end
    end

    # Updates a group through patch
    # @note Redirects to #index if successfull or re-renders #edit if not
    def update
      if @group.update(group_params)
        flash[:notice] = 'Group was successfully updated.'
        redirect_to groups_path
      else
        render :edit
      end
    end

    # Destroys a group
    # @note Redirects to #index on success
    def destroy
      @group.destroy
      
      flash[:notice] = 'Group was successfully destroyed.'
      redirect_to groups_url
    end

    private
    
    # Sets a group from the database using `id` param
    # @note This is a `before_action` callback
    # @private
    def set_group
      @group = Group.find params[:id]
    end

    # Permits group params from forms
    # @private
    def group_params
      params.require(:group).permit(:title, :slug)
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
guts-1.3.2 app/controllers/guts/groups_controller.rb
guts-1.3.1 app/controllers/guts/groups_controller.rb
guts-1.3.0 app/controllers/guts/groups_controller.rb
guts-1.2.2 app/controllers/guts/groups_controller.rb
guts-1.2.1 app/controllers/guts/groups_controller.rb
guts-1.2.0 app/controllers/guts/groups_controller.rb
guts-1.1.1 app/controllers/guts/groups_controller.rb
guts-1.1.0 app/controllers/guts/groups_controller.rb