require_dependency "phcmemberspro/application_controller" module Phcmemberspro class Directory::CategoriesController < ApplicationController # Security & Action Filters before_action :require_user before_action :set_paper_trail_whodunnit before_action :set_directory_category, only: [:edit, :update, :destroy] layout 'layouts/phcmemberspro/directory/directory_all.html.erb' # Directory Category Index def index @directory_categories = Directory::Category.where(oganization_id: membership_info.org_id) end # Directory Category Details def show @versions = PaperTrail::Version.where(item_id: params[:id], item_type: 'Phcmemberspro::Directory::Category') @directory_category = Directory::Category.find(params[:id]) @directory_listings = Directory::Category.where(oganization_id: membership_info.org_id).limit(25) end # New Directory Category def new @directory_category = Directory::Category.new end # Edit Directory Category def edit end # Create Action def create @directory_category = Directory::Category.new(directory_category_params) @directory_category.user_id = current_user.id @directory_category.membership_id = membership_info.id @directory_category.oganization_id = membership_info.org_id if @directory_category.save redirect_to directory_categories_path, notice: 'Category was successfully created.' else render :new end end # Update Action def update @directory_category.user_id = current_user.id @directory_category.membership_id = membership_info.id @directory_category.oganization_id = membership_info.org_id if @directory_category.update(directory_category_params) redirect_to directory_categories_path, notice: 'Category was successfully updated.' else render :edit end end # Delete Action def destroy @directory_category.destroy redirect_to directory_categories_path, notice: 'Category was successfully destroyed.' end private # Grab User Session Key (For ID) def current_user @_current_user ||= AuthRocket::Session.from_token(session[:ar_token]).try(:user) end # Get Current User from Above and Get Membership Info def membership_info AuthRocket::Membership.all(user_id: current_user.id).first end # Common Callbacks def set_directory_category @directory_category = Directory::Category.find(params[:id]) end # whitelist def directory_category_params params.require(:directory_category).permit(:catname, :user_id, :membership_id, :oganization_id) end end end