Sha256: 55082e2fa1b5f56e80011047addcdb854ce91adc1ae5324618a9342d4f15c32b

Contents?: true

Size: 1.68 KB

Versions: 17

Compression:

Stored size: 1.68 KB

Contents

require_dependency "binda/application_controller"

module Binda
  class CategoriesController < ApplicationController
    before_action :set_structure
    before_action :set_category, only: [:show, :edit, :update, :destroy]

    def index
      @categories = @structure.categories.order(:name).all
    end

    def show
      redirect_to action: :edit
    end

    def new
      @category = @structure.categories.build()
    end

    def edit
    end

    def create
      @category = @structure.categories.build(category_params)
      if @category.save
        redirect_to structure_category_path( @structure.slug, @category.slug ), notice: 'Category was successfully created.'
      else
        redirect_to structure_category_path( @structure.slug, @category.slug )
      end
    end

    def update
      if @category.update(category_params)
        redirect_to structure_category_path( @structure.slug, @category.slug ), notice: 'Category was successfully updated.'
      else
        redirect_to structure_category_path( @structure.slug, @category.slug )
      end
    end

    def destroy
      @category.destroy
      redirect_to structure_categories_url( @structure.slug ), notice: 'Category was successfully destroyed.'
    end

    private
      # Use callbacks to share common setup or constraints between actions.
      def set_category
        @category = Category.friendly.find(params[:id])
      end

      # Only allow a trusted parameter "white list" through.
      def category_params
        params.require(:category).permit(:name, :slug, :structure_id, :description, :position)
      end

      def set_structure
        @structure = Structure.friendly.find(params[:structure_id])
      end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
binda-0.1.11 app/controllers/binda/categories_controller.rb
binda-0.1.10 app/controllers/binda/categories_controller.rb
binda-0.1.9 app/controllers/binda/categories_controller.rb
binda-0.1.8 app/controllers/binda/categories_controller.rb
binda-0.1.7 app/controllers/binda/categories_controller.rb
binda-0.1.6 app/controllers/binda/categories_controller.rb
binda-0.1.5 app/controllers/binda/categories_controller.rb
binda-0.1.4 app/controllers/binda/categories_controller.rb
binda-0.1.3 app/controllers/binda/categories_controller.rb
binda-0.1.2 app/controllers/binda/categories_controller.rb
binda-0.1.1 app/controllers/binda/categories_controller.rb
binda-0.1.0 app/controllers/binda/categories_controller.rb
binda-0.0.7 app/controllers/binda/categories_controller.rb
binda-0.0.6 app/controllers/binda/categories_controller.rb
binda-0.0.5 app/controllers/binda/categories_controller.rb
binda-0.0.3 app/controllers/binda/categories_controller.rb
binda-0.0.2 app/controllers/binda/categories_controller.rb