ruby-on-rails - Rails Active Storage Local attachemnt 因神秘错误而失败:未初始化的常量 Analyzable
问题描述
红宝石'2.7.1'/导轨6.0.3.2
我无法让本地活动存储附件工作。这是我的设置:
我跑了:
$ rails active_storage:install
$ rake db:migrate
模型架构
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
模型:
class AmazonUpload < ApplicationRecord
has_many :amazon_upload_recipients
has_one_attached :order_csv
end
我的 storage.yml
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
我的 development.rb 包含:
config.active_storage.service = :local
然后在我的代码中我这样做:
file = File.open(updated_file_path)
@amazon_upload.order_csv.attach(io: file, filename: "hello", content_type: "application/CSV")
最后一行失败了
NameError: uninitialized constant #<Class:0x0000564c2f7e8638>::Analyzable
我可以看到这个错误的唯一其他参考,该人声称他们有一个类型,但我认为这不是问题所在
解决方案
这是 zeitwerk 错误,您只需将 rails 版本升级到 6.1.x,一切都应该正常
如果您不想升级 - 通过添加 application.rb 切换到经典加载模式
config.autoloader = :classic
推荐阅读
- c# - 为什么通过托管的 asp.net Web 应用程序访问 azure blob 容器被拒绝但可以从 localhost 访问?
- python - While 循环未按预期执行
- r - 是什么导致我在 R 中的 union_all 不起作用?
- r - 在 R 中,我可以在所有 wave 中为满足几个特定 wave 中确定的标准的唯一 ID 制作治疗标识符吗?
- python - 如何在 python 中修复“openCV 没有属性 VideoCapture”
- sql - Date with time in JSON_TABLE doesn't save time
- python - 如何从 Python 中的自相关数据中提取清晰的峰值?
- reactjs - 当子级没有该状态作为道具时,父级状态更改会生成子级重新渲染 [Virtual DOM]
- appium - 如何使用 Appium 在 Sauce Labs 中运行应用内购买的自动化测试
- python-3.x - Python 多处理管理器在烧瓶 API 中使用时显示错误