require_dependency "phcpresspro/application_controller" module Phcpresspro class Articles::PostsController < ApplicationController # Security & Action Filters before_action :require_user before_action :authrocket_membership_info before_action :set_paper_trail_whodunnit before_action :set_articles_post, only: [:show, :edit, :update, :destroy] # Article Index def index @articles_posts = Articles::Post.where(oganization_id: authrocket_membership_info.org_id) end # Article Show def show @articles_post = Articles::Post.friendly.find(params[:id]) @versions = PaperTrail::Version.where(item_id: params[:id], item_type: 'Phcpresspro::Articles::Post') end # Article New def new @articles_post = Articles::Post.new end # Article Edit def edit end # POST def create @articles_post = Articles::Post.new(articles_post_params) @articles_post.user_id = current_user.id @articles_post.user_name = current_user.username @articles_post.membership_id = authrocket_membership_info.id @articles_post.oganization_id = authrocket_membership_info.org_id if @articles_post.save @articles_post.connections.build redirect_to articles_posts_url, notice: 'Post was successfully created.' else render :new end end # PATCH/PUT def update @articles_post.user_id = current_user.id @articles_post.user_name = current_user.username @articles_post.membership_id = authrocket_membership_info.id @articles_post.oganization_id = authrocket_membership_info.org_id if @articles_post.update(articles_post_params) @articles_post.connections.build redirect_to articles_posts_url, notice: 'Post was successfully updated.' else render :edit end end # DELETE def destroy @articles_post.destroy redirect_to articles_posts_url, notice: 'Post was successfully destroyed.' end private # Common Callbacks def set_articles_post @articles_post = Articles::Post.friendly.find(params[:id]) end # Params Whitelist def articles_post_params params.require(:articles_post).permit(:psttitle, :psttext, :pststatus, :pstimage, :remove_pstimage, :slug, :user_id, :user_name, :membership_id, :oganization_id, category_ids: []) end end end