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