Sha256: 6dc73776514ce648a381c591f7817d8ae4da5d828df43106e2dea64e97a282ce

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require_dependency "phcpresspro/application_controller"

module Phcpresspro
  class Article::PostsController < ApplicationController

    # Include Core Helpers, Security & Action Filters
    include Phccorehelpers::PhcpluginsproHelper
    before_action :authenticate_user!
    before_action :set_paper_trail_whodunnit
    before_action :set_article_post, only: [:edit, :update, :destroy]

    # INDEX
    def index
      @article_posts = Phcpresspro::Article::Post.all
    end

    # SHOW
    def show
      @article_post = Phcpresspro::Article::Post.friendly.find(params[:id])
      @versions = Phcpresspro::PostVersions.where(item_id: params[:id], item_type: 'Phcpresspro::Article::Post')
    end

    # NEW
    def new
      @article_post = Phcpresspro::Article::Post.new
    end

    # EDIT
    def edit
    end

    # CREATE
    def create
      @article_post = Phcpresspro::Article::Post.new(article_post_params)
      @article_post.user_id = current_user.id
      if @article_post.save
        redirect_to article_posts_url, :flash => { :success => 'Post was successfully created.' }
      else
        render :new
      end
    end

    # UPDATE
    def update
      if @article_post.update(article_post_params)
        redirect_to article_posts_url, :flash => { :success => 'Post was successfully updated.' }
      else
        render :edit
      end
    end

    # DELETE
    def destroy
      @article_post.destroy
      redirect_to article_posts_url, :flash => { :error => 'Post was successfully destroyed.' }
    end

    private

    # Common Callbacks
    def set_article_post
      @article_post = Phcpresspro::Article::Post.find(params[:id])
    end

    # Whitelist
    def article_post_params
      params.require(:article_post).permit(:post_title, :post_text, :post_status, :post_image, :remove_post_image, :slug, :user_id, category_ids: [])
    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
phcpresspro-83.0.0 app/controllers/phcpresspro/article/posts_controller.rb