Sha256: e5d4dc656323ff79525405d41538cbe86715eb008f3cadc48f81780334f1715c

Contents?: true

Size: 1.99 KB

Versions: 4

Compression:

Stored size: 1.99 KB

Contents

require_dependency "phcmemberspro/application_controller"

module Phcmemberspro
  class Directory::CategoriesController < ApplicationController

    # Include Core Helpers, Security & Action Filters
    include PhcdevworksCore::PhcdevPluginsHelper
    before_action :authenticate_user!
    before_action :set_paper_trail_whodunnit
    before_action :set_directory_category, only: [:show, :edit, :update, :destroy]

    # INDEX
    def index
      @directory_categories = Directory::Category.where(org_id: current_user.org_id)
    end

    # SHOW
    def show
      @directory_category = Directory::Category.find(params[:id])
      @directory_category_versions = Phcmemberspro::CategoryVersions.where(item_id: @directory_category, item_type: 'Phcmemberspro::Directory::Category')
    end

    # NEW
    def new
      @directory_category = Directory::Category.new
    end

    # EDIT
    def edit
    end

    # CREATE
    def create
      @directory_category = Directory::Category.new(directory_category_params)
      @directory_category.user_id = current_user.id
      @directory_category.org_id = current_user.org_id
      if @directory_category.save
        redirect_to directory_categories_url, :flash => { :success => 'Category was successfully created.' }
      else
        render :new
      end
    end

    # UPDATE
    def update
      if @directory_category.update(directory_category_params)
        redirect_to directory_categories_url, :flash => { :success => 'Category was successfully updated.' }
      else
        render :edit
      end
    end

    # DELETE
    def destroy
      @directory_category.destroy
      redirect_to directory_categories_url, :flash => { :error => 'Category was successfully destroyed.' }
    end

    private

    # Common Callbacks
    def set_directory_category
      @directory_category = Directory::Category.find(params[:id])
    end

    # Whitelist
    def directory_category_params
      params.require(:directory_category).permit(:category_name, :slug, :user_id)
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
phcmemberspro-92.0.3 app/controllers/phcmemberspro/directory/categories_controller.rb
phcmemberspro-92.0.2 app/controllers/phcmemberspro/directory/categories_controller.rb
phcmemberspro-92.0.1 app/controllers/phcmemberspro/directory/categories_controller.rb
phcmemberspro-92.0.0 app/controllers/phcmemberspro/directory/categories_controller.rb