Sha256: 6acc78f303c7e94ac0de49d90aed9e7d50bbabd9e6b314a06fde2155a1e97086

Contents?: true

Size: 1.6 KB

Versions: 3

Compression:

Stored size: 1.6 KB

Contents

module Spina
  module Admin
    class AttachmentsController < AdminController
      before_action :set_breadcrumbs

      authorize_resource class: Attachment

      layout "spina/admin/media_library"

      def index
        add_breadcrumb I18n.t('spina.website.documents'), spina.admin_attachments_path
        @attachments = Attachment.file_attached.sorted
        @attachment = Attachment.new
      end

      def create
        @attachment = Attachment.create(attachment_params)
      end

      def destroy
        @attachment = Attachment.find(params[:id])
        @attachment.destroy
        redirect_to spina.admin_attachments_url
      end

      def select
        @selected_attachment_id = Attachment.find_by(id: params[:selected_attachment_id]).try(:id)
        @attachments = Attachment.order_by_ids(@selected_attachment_id).file_attached.sorted
        @attachment = Attachment.new
      end

      def insert
        @attachment = Attachment.find(params[:attachment_id])
      end

      def select_collection
        @selected_attachment_ids = Attachment.where(id: params[:selected_attachment_ids]).ids
        @attachments = Attachment.order_by_ids(@selected_attachment_ids).file_attached.sorted
        @attachment = Attachment.new
      end

      def insert_collection
        @attachments = Attachment.where(id: params[:attachment_ids])
      end

      private

      def set_breadcrumbs
        add_breadcrumb I18n.t('spina.website.media_library'), spina.admin_media_library_path
      end

      def attachment_params
        params.require(:attachment).permit(:file, :page_id, :_destroy)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
spina-0.11.1 app/controllers/spina/admin/attachments_controller.rb
spina-0.11.0 app/controllers/spina/admin/attachments_controller.rb
spina-0.10.0 app/controllers/spina/admin/attachments_controller.rb