Sha256: 03ff0287f75e8d3c9e08175b925b77b3d565048b4fef826ebf801a8b6b4d000d

Contents?: true

Size: 1.42 KB

Versions: 21

Compression:

Stored size: 1.42 KB

Contents

# frozen_string_literal: true

class Admin::PostTypesController < Admin::BaseController
  before_action :set_post_type, only: [:edit, :update, :destroy]

  def index
    @post_types = PostType.all
    @post_type = PostType.new
  end

  def edit
    @post_types = PostType.all
  end

  def create
    @post_type = PostType.new(post_type_params)

    if @post_type.save
      redirect_to admin_post_types_url, notice: "Post type was successfully created."
    else
      render :index
    end
  end

  def update
    if @post_type.update(post_type_params)
      redirect_to admin_post_types_url, notice: "Post type was successfully updated."
    else
      render :edit
    end
  end

  def destroy
    # Reset all Articles from the PostType we're destroying to the default PostType
    # Wrap it in a transaction for safety
    @post_type.transaction do
      Article.where("post_type = ?", @post_type.permalink).each do |article|
        article.post_type = "read"
        article.save
      end
      @post_type.destroy
    end
    redirect_to admin_post_types_url, notice: "Post was successfully destroyed."
  end

  private

  # Use callbacks to share common setup or constraints between actions.
  def set_post_type
    @post_type = PostType.find(params[:id])
  end

  # Never trust parameters from the scary internet, only allow the white list through.
  def post_type_params
    params.require(:post_type).permit(:name, :description)
  end
end

Version data entries

21 entries across 21 versions & 2 rubygems

Version Path
HornsAndHooves-publify_core-10.5.0 app/controllers/admin/post_types_controller.rb
HornsAndHooves-publify_core-10.4.0 app/controllers/admin/post_types_controller.rb
HornsAndHooves-publify_core-10.3.0 app/controllers/admin/post_types_controller.rb
HornsAndHooves-publify_core-10.2.0 app/controllers/admin/post_types_controller.rb
publify_core-9.2.10 app/controllers/admin/post_types_controller.rb
HornsAndHooves-publify_core-10.1.1 app/controllers/admin/post_types_controller.rb
HornsAndHooves-publify_core-10.1.0 app/controllers/admin/post_types_controller.rb
HornsAndHooves-publify_core-10.0.3 app/controllers/admin/post_types_controller.rb
HornsAndHooves-publify_core-10.0.2 app/controllers/admin/post_types_controller.rb
HornsAndHooves-publify_core-10.0.1 app/controllers/admin/post_types_controller.rb
HornsAndHooves-publify_core-10.0.0 app/controllers/admin/post_types_controller.rb
publify_core-9.2.9 app/controllers/admin/post_types_controller.rb
publify_core-9.2.8 app/controllers/admin/post_types_controller.rb
publify_core-9.2.7 app/controllers/admin/post_types_controller.rb
publify_core-9.2.6 app/controllers/admin/post_types_controller.rb
publify_core-9.2.5 app/controllers/admin/post_types_controller.rb
publify_core-9.2.4 app/controllers/admin/post_types_controller.rb
publify_core-9.2.3 app/controllers/admin/post_types_controller.rb
publify_core-9.2.2 app/controllers/admin/post_types_controller.rb
publify_core-9.2.1 app/controllers/admin/post_types_controller.rb