Sha256: 56d35ad28a8d8043215a659e5c43ceae730d7963a3cd6241e026704f72699627

Contents?: true

Size: 1.74 KB

Versions: 13

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true
require_dependency "think_feel_do_engine/application_controller"

module ThinkFeelDoEngine
  module BitMaker
    # Enables creation and deletion of SlideshowAnchors.
    class SlideshowAnchorsController < ApplicationController
      before_action :authenticate_user!, :set_arm, :find_slideshow

      rescue_from ActiveRecord::RecordNotFound, with: :record_not_found

      def create
        unless params[:slideshow_anchor]
          return destroy if params[:id_to_destroy].present?
          return render(js: "")
        end

        authorize! :create, SlideshowAnchor
        @slideshow_anchor = SlideshowAnchor.new(anchor_params)

        if @slideshow_anchor.save
          render "create", locals: { notice: "Anchor saved" }
        else
          render "create", locals: { alert: "Unable to save Anchor" }
        end
      end

      def destroy
        authorize! :destroy, SlideshowAnchor
        @slideshow_anchor = SlideshowAnchor.find(params[:id_to_destroy])

        if @slideshow_anchor.destroy
          render "destroy", locals: { notice: "Anchor deleted" }
        else
          render "destroy", locals: { alert: model_errors }
        end
      end

      private

      def find_slideshow
        @slideshow = @arm.bit_core_slideshows.find(params[:slideshow_id])
      end

      def record_not_found
        render "destroy", locals: { alert: "Not found" }
      end

      def model_errors
        @slideshow_anchor.errors.full_messages.join(", ")
      end

      def anchor_params
        params.require(:slideshow_anchor)
              .permit(:target_name)
              .merge(bit_core_slideshow_id: @slideshow.id)
      end

      def set_arm
        @arm = Arm.find(params[:arm_id])
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
think_feel_do_engine-3.22.9 app/controllers/think_feel_do_engine/bit_maker/slideshow_anchors_controller.rb
think_feel_do_engine-3.22.8 app/controllers/think_feel_do_engine/bit_maker/slideshow_anchors_controller.rb
think_feel_do_engine-3.22.7 app/controllers/think_feel_do_engine/bit_maker/slideshow_anchors_controller.rb
think_feel_do_engine-3.22.6 app/controllers/think_feel_do_engine/bit_maker/slideshow_anchors_controller.rb
think_feel_do_engine-3.22.5 app/controllers/think_feel_do_engine/bit_maker/slideshow_anchors_controller.rb
think_feel_do_engine-3.22.4 app/controllers/think_feel_do_engine/bit_maker/slideshow_anchors_controller.rb
think_feel_do_engine-3.22.2 app/controllers/think_feel_do_engine/bit_maker/slideshow_anchors_controller.rb
think_feel_do_engine-3.22.1 app/controllers/think_feel_do_engine/bit_maker/slideshow_anchors_controller.rb
think_feel_do_engine-3.22.0 app/controllers/think_feel_do_engine/bit_maker/slideshow_anchors_controller.rb
think_feel_do_engine-3.21.2 app/controllers/think_feel_do_engine/bit_maker/slideshow_anchors_controller.rb
think_feel_do_engine-3.21.1 app/controllers/think_feel_do_engine/bit_maker/slideshow_anchors_controller.rb
think_feel_do_engine-3.21.0 app/controllers/think_feel_do_engine/bit_maker/slideshow_anchors_controller.rb
think_feel_do_engine-3.20.1 app/controllers/think_feel_do_engine/bit_maker/slideshow_anchors_controller.rb