Sha256: f6cbb15615697210406c0dcf76f52e433fa8d69e708bbc5c7ce8761ea337e447

Contents?: true

Size: 1.97 KB

Versions: 7

Compression:

Stored size: 1.97 KB

Contents

require_dependency "phcpresspro/application_controller"

module Phcpresspro
  class Article::CategoriesController < ApplicationController

    # Include Core Helpers, Security & Action Filters
    include Phccorehelpers::PhcpluginsproHelper
    before_action :authenticate_user!
    before_action :set_paper_trail_whodunnit
    before_action :set_article_category, only: [:edit, :update, :destroy]

    # INDEX
    def index
      @article_categories = Phcpresspro::Article::Category.where(org_id: current_user.org_id)
    end

    # SHOW
    def show
      @article_category = Phcpresspro::Article::Category.friendly.find(params[:id])
      @versions = Phcpresspro::CategoryVersions.where(item_id: params[:id], item_type: 'Phcpresspro::Article::Category')
    end

    # NEW
    def new
      @article_category = Phcpresspro::Article::Category.new
    end

    # EDIT
    def edit
    end

    # CREATE
    def create
      @article_category = Phcpresspro::Article::Category.new(article_category_params)
      @article_category.user_id = current_user.id
      @article_category.org_id = current_user.org_id
      if @article_category.save
        redirect_to article_categories_url, :flash => { :success => 'Category was successfully created.' }
      else
        render :new
      end
    end

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

    # DELETE
    def destroy
      @article_category.destroy
      redirect_to article_categories_url, :flash => { :success => 'Category was successfully destroyed.' }
    end

    private

    # Common Callbacks
    def set_article_category
      @article_category = Phcpresspro::Article::Category.find(params[:id])
    end

    # Whitelist
    def article_category_params
      params.require(:article_category).permit(:category_name, :slug, :user_id)
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
phcpresspro-86.4.0 app/controllers/phcpresspro/article/categories_controller.rb
phcpresspro-86.3.0 app/controllers/phcpresspro/article/categories_controller.rb
phcpresspro-86.2.0 app/controllers/phcpresspro/article/categories_controller.rb
phcpresspro-86.1.0 app/controllers/phcpresspro/article/categories_controller.rb
phcpresspro-86.0.0 app/controllers/phcpresspro/article/categories_controller.rb
phcpresspro-85.0.0 app/controllers/phcpresspro/article/categories_controller.rb
phcpresspro-84.0.0 app/controllers/phcpresspro/article/categories_controller.rb