Sha256: 57c5c6734ff5556c2e4684f44bf72bdb199159d5925ffc2a80fdfaff46ed0d8e

Contents?: true

Size: 1.21 KB

Versions: 15

Compression:

Stored size: 1.21 KB

Contents

module Dorsale
  module Alexandrie
    class AttachmentsController < ::Dorsale::ApplicationController
      def create
        @attachment = ::Dorsale::Alexandrie::Attachment.new(attachment_params)

        authorize! :create, @attachment

        if @attachment.save
          flash[:notice] = t("messages.attachments.create_ok")
        else
          ap @attachment.errors
          flash[:alert] = t("messages.attachments.create_error")
        end

        redirect_to_back_url
      end

      def destroy
        @attachment = ::Dorsale::Alexandrie::Attachment.find params[:id]

        authorize! :delete, @attachment

        if @attachment.destroy
          flash[:notice] = t("messages.attachments.delete_ok")
        else
          flash[:alert] = t("messages.attachments.delete_error")
        end

        redirect_to_back_url
      end

      private

      def permitted_params_for_attachment
        [
          :attachable_id,
          :attachable_type,
          :file,
        ]
      end

      def attachment_params
        params.require(:attachment).permit(permitted_params_for_attachment)
      end

      def redirect_to_back_url
        redirect_to params[:back_url] || request.referer
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
dorsale-2.1.13 app/controllers/dorsale/alexandrie/attachments_controller.rb
dorsale-2.1.12 app/controllers/dorsale/alexandrie/attachments_controller.rb
dorsale-2.1.11 app/controllers/dorsale/alexandrie/attachments_controller.rb
dorsale-2.1.10 app/controllers/dorsale/alexandrie/attachments_controller.rb
dorsale-2.1.9 app/controllers/dorsale/alexandrie/attachments_controller.rb
dorsale-2.1.8 app/controllers/dorsale/alexandrie/attachments_controller.rb
dorsale-2.1.7 app/controllers/dorsale/alexandrie/attachments_controller.rb
dorsale-2.1.6 app/controllers/dorsale/alexandrie/attachments_controller.rb
dorsale-2.1.5 app/controllers/dorsale/alexandrie/attachments_controller.rb
dorsale-2.1.4 app/controllers/dorsale/alexandrie/attachments_controller.rb
dorsale-2.1.3 app/controllers/dorsale/alexandrie/attachments_controller.rb
dorsale-2.1.2 app/controllers/dorsale/alexandrie/attachments_controller.rb
dorsale-2.1.1 app/controllers/dorsale/alexandrie/attachments_controller.rb
dorsale-2.1.0 app/controllers/dorsale/alexandrie/attachments_controller.rb
dorsale-2.0.1 app/controllers/dorsale/alexandrie/attachments_controller.rb