Sha256: 2382745df534730a908a07f2ce139dfc7b4e20e415de31f08138b4936e7cfe56

Contents?: true

Size: 1.86 KB

Versions: 5

Compression:

Stored size: 1.86 KB

Contents

require_dependency "phcpress/application_controller"

module Phcpress
  class Article::CategoriesController < ApplicationController

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

    # INDEX
    def index
      @article_categories = Phcpress::Article::Category.all
    end

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

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

    # EDIT
    def edit
    end

    # CREATE
    def create
      @article_category = Phcpress::Article::Category.new(article_category_params)
      @article_category.user_id = current_user.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 = Phcpress::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

5 entries across 5 versions & 1 rubygems

Version Path
phcpress-57.0.4 app/controllers/phcpress/article/categories_controller.rb
phcpress-57.0.3 app/controllers/phcpress/article/categories_controller.rb
phcpress-57.0.2 app/controllers/phcpress/article/categories_controller.rb
phcpress-57.0.1 app/controllers/phcpress/article/categories_controller.rb
phcpress-57.0.0 app/controllers/phcpress/article/categories_controller.rb