Sha256: d6ae51f0255a6f69cb9d341236ac626f21484314c578c22a18d499d54f91b985

Contents?: true

Size: 1.04 KB

Versions: 28

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Admin
  class AttachmentsController < Admin::AdminController
    before_action :find_attachment, only: %i[update]

    def create
      @attachment = Attachment.create(
        attachment_params.merge(user: current_user)
      )
      return unless @attachment.valid?

      respond_to do |format|
        format.json do
          render_attachment(@attachment)
        end
      end
    end

    def update
      @attachment.update(attachment_params)
      respond_to do |format|
        format.json { render_attachment(@attachment) }
      end
    end

    protected

    def attachment_params
      params.require(:attachment).permit(
        :file,
        localized_attributes.index_with do |_a|
          I18n.available_locales
        end
      )
    end

    def localized_attributes
      %i[name description]
    end

    def find_attachment
      @attachment = Attachment.find(params[:id])
    end

    def render_attachment(attachment)
      render json: Admin::AttachmentResource.new(attachment)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
pages_core-3.15.5 app/controllers/admin/attachments_controller.rb
pages_core-3.15.4 app/controllers/admin/attachments_controller.rb
pages_core-3.15.3 app/controllers/admin/attachments_controller.rb
pages_core-3.15.2 app/controllers/admin/attachments_controller.rb
pages_core-3.15.1 app/controllers/admin/attachments_controller.rb
pages_core-3.14.0 app/controllers/admin/attachments_controller.rb
pages_core-3.13.0 app/controllers/admin/attachments_controller.rb
pages_core-3.12.7 app/controllers/admin/attachments_controller.rb
pages_core-3.12.6 app/controllers/admin/attachments_controller.rb
pages_core-3.12.5 app/controllers/admin/attachments_controller.rb
pages_core-3.12.4 app/controllers/admin/attachments_controller.rb
pages_core-3.12.3 app/controllers/admin/attachments_controller.rb
pages_core-3.12.2 app/controllers/admin/attachments_controller.rb
pages_core-3.12.1 app/controllers/admin/attachments_controller.rb
pages_core-3.12.0 app/controllers/admin/attachments_controller.rb
pages_core-3.11.3 app/controllers/admin/attachments_controller.rb
pages_core-3.11.2 app/controllers/admin/attachments_controller.rb
pages_core-3.11.1 app/controllers/admin/attachments_controller.rb
pages_core-3.11.0 app/controllers/admin/attachments_controller.rb
pages_core-3.10.2 app/controllers/admin/attachments_controller.rb