require_dependency "phcpresspro/application_controller" module Phcpresspro class Modules::CategoriesController < ApplicationController # Security & Action Filters before_action :authenticate_user! before_action :set_paper_trail_whodunnit before_action :set_modules_category, only: [:show, :edit, :update, :destroy] # Categories Index def index @modules_categories = Modules::Category.where(org_id: current_user.org_id) end # Categories Show def show @modules_category = Modules::Category.friendly.find(params[:id]) @versions = PaperTrail::Version.where(item_id: params[:id], item_type: 'Phcpresspro::Modules::Category') end # Categories New def new @modules_category = Modules::Category.new @modules_category.user_id = current_user.id @modules_category.org_id = current_user.org_id end # Categories Edit def edit end # POST def create @modules_category = Modules::Category.new(modules_category_params) @modules_category.user_id = current_user.id @modules_category.org_id = current_user.org_id if @modules_category.save redirect_to modules_categories_url, notice: 'Category was successfully created.' else render :new end end # PATCH/PUT def update @modules_category.user_id = current_user.id @modules_category.org_id = current_user.org_id if @modules_category.update(modules_category_params) redirect_to modules_categories_url, notice: 'Category was successfully updated.' else render :edit end end # DELETE def destroy @modules_category.destroy redirect_to modules_categories_url, notice: 'Category was successfully destroyed.' end private # Common Callbacks def set_modules_category @modules_category = Modules::Category.friendly.find(params[:id]) end # Whitelist def modules_category_params params.require(:modules_category).permit(:catname, :slug, :user_id, :org_id) end end end