Sha256: f609c6e56d95dee5190e6881d040abc4e1cefb7c32427c25004ad94c28ca2f96

Contents?: true

Size: 1.59 KB

Versions: 5

Compression:

Stored size: 1.59 KB

Contents

require 'rails_admin/config/fields/types/multiple_file_upload'

module RailsAdmin
  module Config
    module Fields
      module Types
        class MultipleActiveStorage < RailsAdmin::Config::Fields::Types::MultipleFileUpload
          RailsAdmin::Config::Fields::Types.register(self)

          class ActiveStorageAttachment < RailsAdmin::Config::Fields::Types::MultipleFileUpload::AbstractAttachment
            register_instance_option :thumb_method do
              {resize: '100x100>'}
            end

            register_instance_option :delete_key do
              value.id
            end

            register_instance_option :image? do
              if value
                value.filename.to_s.split('.').last =~ /jpg|jpeg|png|gif|svg/i
              end
            end

            def resource_url(thumb = false)
              return nil unless value
              if thumb && value.variable?
                variant = value.variant(thumb_method)
                Rails.application.routes.url_helpers.rails_blob_representation_path(
                  variant.blob.signed_id, variant.variation.key, variant.blob.filename, only_path: true
                )
              else
                Rails.application.routes.url_helpers.rails_blob_path(value, only_path: true)
              end
            end
          end

          register_instance_option :attachment_class do
            ActiveStorageAttachment
          end

          register_instance_option :delete_method do
            "remove_#{name}" if bindings[:object].respond_to?("remove_#{name}")
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rails_admin-1.4.3 lib/rails_admin/config/fields/types/multiple_active_storage.rb
rails_admin-2.0.0.beta lib/rails_admin/config/fields/types/multiple_active_storage.rb
rails_admin-1.4.2 lib/rails_admin/config/fields/types/multiple_active_storage.rb
rails_admin-1.4.1 lib/rails_admin/config/fields/types/multiple_active_storage.rb
rails_admin-1.4.0 lib/rails_admin/config/fields/types/multiple_active_storage.rb