DEV Community

Discussion on: Extend Rails ActiveStorage disk service for multitenant

Collapse
 
mgharbik profile image
Gharbi Mohammed • Edited

Hey Adnan, thanks for the post, for S3 service I just solved it this way:

# lib/active_storage/service/tenant_s3_service.rb
# extend s3 service
require 'active_storage/service/s3_service'

module ActiveStorage
  class Service::TenantS3Service < Service::S3Service
    private

    def object_for(key)
      current_tenant = Apartment::Tenant.current
      bucket.object File.join(current_tenant, key)
    end
  end
end
Enter fullscreen mode Exit fullscreen mode

Then:

amazon:
  service: TenantS3
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mkhairi profile image
Mohd Khairi

That awesome 🤩 !