require_dependency "phcpresspro/application_controller" module Phcpresspro class Article::CategoriesController < ApplicationController # Security, Layouts & Action Filters before_action :authenticate_user! before_action :phc_accounts_pro_admin_only before_action :set_paper_trail_whodunnit before_action :set_article_category, only: [:show, :edit, :update, :destroy] # Categories Index def index @article_categories = Article::Category.where(org_id: current_user.org_id) end # Categories Show def show @article_category = Article::Category.friendly.find(params[:id]) @versions = PaperTrail::Version.where(item_id: params[:id], item_type: 'Phcpresspro::Article::Category') end # Categories New def new @article_category = Article::Category.new @article_category.user_id = current_user.id @article_category.org_id = current_user.org_id end # Categories Edit def edit end # POST def create @article_category = 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, notice: 'Category was successfully created.' else render :new end end # PATCH/PUT def update @article_category.user_id = current_user.id @article_category.org_id = current_user.org_id if @article_category.update(article_category_params) redirect_to article_categories_url, notice: 'Category was successfully updated.' else render :edit end end # DELETE def destroy @article_category.destroy redirect_to article_categories_url, notice: 'Category was successfully destroyed.' end private # Use callbacks to share common setup or constraints between actions. def set_article_category @article_category = Article::Category.find(params[:id]) end # Only allow a trusted parameter "white list" through. def article_category_params params.require(:article_category).permit(:catname, :slug, :user_id, :org_id) end end end