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