Sha256: 6b102ee613ca1ebd95066159d50e89e7de000b50bb7971d66f23590c0a82af5a

Contents?: true

Size: 1.41 KB

Versions: 1

Compression:

Stored size: 1.41 KB

Contents

require_dependency 'cavy/application_controller'

module Cavy
  class ItemGroupsController < ApplicationController
    before_action :set_item_group, only: %i[show edit update destroy]
    layout 'cavy/admin_layout'

    def index
      @item_groups = ItemGroup.all
    end

    def show
      @items = @item_group.items.order('position asc')
    end

    def new
      @item_group = ItemGroup.new
    end

    def edit; end

    def create
      @item_group = ItemGroup.new(item_group_params)

      if @item_group.save
        redirect_to item_groups_path, flash: { success: 'Admin item group was successfully created.' }
      else
        render action: 'new'
      end
    end

    def update
      if @item_group.update_attributes(item_group_params)
        redirect_to item_groups_path, flash: { success: 'Admin item group was successfully updated.' }
      else
        render action: 'edit'
      end
    end

    def update_order
      params[:item].each_with_index do |id, index|
        Cavy::Item.find(id).set(position: index + 1)
      end
      render nothing: true
    end

    def destroy
      @item_group.destroy
      redirect_to item_groups_url, flash: { success: 'Admin item group was successfully destroyed.' }
    end

    private

    def set_item_group
      @item_group = ItemGroup.find(params[:id])
    end

    def item_group_params
      params.require(:item_group).permit(:title, :param_string)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cavy-0.1.0.beta2 app/controllers/cavy/item_groups_controller.rb