5

ruby '2.7.1' / rails 6.0.3.2

I can't get local active storage attachements to work. Here is my setup:

I have run:

$ rails active_storage:install
$ rake db:migrate

Model schema

  create_table "amazon_uploads" do |t|
    t.string "status"
    t.string "order_csv"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end

model:

class AmazonUpload < ApplicationRecord
  has_many :amazon_upload_recipients

  has_one_attached :order_csv
end

my storage.yml

test:
  service: Disk
  root: <%= Rails.root.join("tmp/storage") %>

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

my development.rb contains:

  config.active_storage.service = :local

And then in my code I do:

    file = File.open(updated_file_path)
    @amazon_upload.order_csv.attach(io: file, filename: "hello", content_type: "application/CSV")

the last line fails with

NameError: uninitialized constant #<Class:0x0000564c2f7e8638>::Analyzable

The only other reference I can see to this error the person claims they had a type but I don't think that's the issue here

Andrew
  • 942
  • 10
  • 26

2 Answers2

2

it's zeitwerk bug you can just upgrade your rails version to 6.1.x and everything should work fine

if you don't want to upgrade - switch to the classic load mode by adding in application.rb

config.autoloader = :classic
0

In my case I just add

include ActiveStorage::Blob::Analyzable
vladislav
  • 133
  • 1
  • 2
  • 8