Uninitialized constant ActiveStorage::Service::DiskService

I have some code that looks like this:

    def wicked_blob_path(active_storage_attachment)
        service = active_storage_attachment.service
        case service
        when ActiveStorage::Service::DiskService
            service.path_for(active_storage_attachment.blob.key)
        when ActiveStorage::Service::S3Service
            active_storage_attachment.service_url
        else
            raise "Unsupported ActiveStorage service for WickedPDF integration: #{service.name}"
        end
    end

It seems to barf in production with an error: uninitialized constant ActiveStorage::Service::DiskService

I feel like this should be initialized, but it isn’t.

It appears to be a part of the Rails standard library: ActiveStorage::Service::DiskService

I have a section in my config/storage.yml file for it:

local:
  service: Disk
  root: <%= Rails.root.join("storage") %>

I’m using Rails version 6.0.3.1.

I could maybe re-factor the method to first check if defined? ActiveStorage::Service::DiskService but that doesn’t seem like the ideal solution, especially if this service should be defined.

    def wicked_blob_path(active_storage_attachment)
        service = active_storage_attachment.service
        # put a break point here and check service.class
        case service
        when ActiveStorage::Service::DiskService
            service.path_for(active_storage_attachment.blob.key)
        when ActiveStorage::Service::S3Service
            active_storage_attachment.service_url
        else
            raise "Unsupported ActiveStorage service for WickedPDF integration: #{service.name}"
        end
    end

Could you put a breakpoint in above mentioned place and check service.class there?

I was facing the same issue.

Fixed it the following way

  def wicked_blob_path(active_storage_attachment)
    service = active_storage_attachment.service
    service_name = service.class.name

    case service_name
    when 'ActiveStorage::Service::DiskService'
      service.path_for(active_storage_attachment.blob.key)
    when 'ActiveStorage::Service::S3Service'
      active_storage_attachment.url
    else
      raise "Unsupported ActiveStorage service for WickedPDF integration: #{service_name}"
    end
  end