2

I have recently updated Rails to 6.1 to support multiple buckets uploads in ActiveStorage. However, after upgrading, updating ActiveStorage, deleting everything and reinstalling again, it still does not work. I followed this guide. I also followed this. Here's my implementation:

# storage.yaml
amazon_contracts:
  service: S3
  access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
  secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
  region: sa-east-1
  bucket: contracts-raw-ac1

amazon_templates:
  service: S3
  access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>
  secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>
  region: sa-east-1
  bucket: templates-raw-ac1
# development.rb (default service to be used)
config.active_storage.service = :amazon_contracts
# template.rb
has_one_attached :template, service: :amazon_templates
# contract.rb
has_many_attached :contracts, service: :amazon_contracts

However, both the template and contract uploads go directly to the contracts bucket. I have tried removing the default service from the development.rb, but I get cannot get name of nil Class error. Any help is very much appreciated.

  • 1
    Were you able to figure out what went wrong? – DrewBaumann Aug 17 '21 at 23:39
  • 1
    @DrewBaumann, no. I followed this setup and Jonathan's, but still same behavior (file keeps being uploaded to one single bucket). I started to think that the problem is due to me updating to Rails 6 and not fully updating ActiveStorage. – Vinicius Martinson Sep 25 '21 at 22:19
  • I have a fresh new Rails 6.1+ intallation and I'm facing the same problem, so I don't think it's related to your upgrade. It's like the service: part is disregarded entirely. – Ivan Raszl Oct 27 '21 at 08:03

1 Answers1

0

I followed your setup almost exactly, and it worked as intended. The only way I could replicate is if I redefined the attachment has_one/has_many relationships later in the model files. Is it possible you've done something like this?

# template.rb
has_one_attached :template, service: :amazon_templates

# ...
# ... potentially many lines of code ...
# ...

has_one_attached :template
Jonathan Thom
  • 56
  • 1
  • 4