diff --git a/lib/rails_admin/config/fields/types/active_storage.rb b/lib/rails_admin/config/fields/types/active_storage.rb index 415750a5e..b2c02265e 100644 --- a/lib/rails_admin/config/fields/types/active_storage.rb +++ b/lib/rails_admin/config/fields/types/active_storage.rb @@ -18,10 +18,7 @@ class ActiveStorage < RailsAdmin::Config::Fields::Types::FileUpload end register_instance_option :image? do - if value - mime_type = Mime::Type.lookup_by_extension(value.filename.extension_without_delimiter) - mime_type.to_s.match?(/^image/) - end + value && (value.representable? || mime_type(value.filename).to_s.match?(/^image/)) end register_instance_option :eager_load do @@ -43,11 +40,11 @@ class ActiveStorage < RailsAdmin::Config::Fields::Types::FileUpload def resource_url(thumb = false) return nil unless value - if thumb && value.variable? + if thumb && value.representable? thumb = thumb_method if thumb == true - variant = value.variant(thumb) + repr = value.representation(thumb) Rails.application.routes.url_helpers.rails_blob_representation_path( - variant.blob.signed_id, variant.variation.key, variant.blob.filename, only_path: true + repr.blob.signed_id, repr.variation.key, repr.blob.filename, only_path: true ) else Rails.application.routes.url_helpers.rails_blob_path(value, only_path: true) @@ -58,6 +55,10 @@ def value attachment = super attachment if attachment&.attached? end + + def mime_type(filename_obj) + Mime::Type.lookup_by_extension(filename_obj.extension_without_delimiter) + end end end end diff --git a/lib/rails_admin/config/fields/types/multiple_active_storage.rb b/lib/rails_admin/config/fields/types/multiple_active_storage.rb index 9c1ebb2c2..3df317581 100644 --- a/lib/rails_admin/config/fields/types/multiple_active_storage.rb +++ b/lib/rails_admin/config/fields/types/multiple_active_storage.rb @@ -23,24 +23,25 @@ class ActiveStorageAttachment < RailsAdmin::Config::Fields::Types::MultipleFileU end register_instance_option :image? do - if value - mime_type = Mime::Type.lookup_by_extension(value.filename.extension_without_delimiter) - mime_type.to_s.match?(/^image/) - end + value && (value.representable? || mime_type(value.filename).to_s.match?(/^image/)) end def resource_url(thumb = false) return nil unless value - if thumb && value.variable? - variant = value.variant(thumb_method) + if thumb && value.representable? + repr = value.representation(thumb_method) Rails.application.routes.url_helpers.rails_blob_representation_path( - variant.blob.signed_id, variant.variation.key, variant.blob.filename, only_path: true + repr.blob.signed_id, repr.variation.key, repr.blob.filename, only_path: true ) else Rails.application.routes.url_helpers.rails_blob_path(value, only_path: true) end end + + def mime_type(filename_obj) + Mime::Type.lookup_by_extension(filename_obj.extension_without_delimiter) + end end register_instance_option :attachment_class do