所以我决定添加一个url
ActiveStorage::Attachment 对象的 attr_accessor。
In 发展该补丁会保留一段时间,直到它看起来“已经丢失”。这意味着它可以工作几分钟,然后就不再工作了。然后我需要重新启动服务器才能再次应用补丁。我相信我没有正确修补,我需要这方面的建议。
这是我尝试过的:
lib/ext/active_storage/attachment.rb
第一次尝试 :
module ActiveStorageUrl
extend ActiveSupport::Concern
included do
attr_accessor :url
end
end
ActiveStorage::Attachment.send :include, ActiveStorageUrl
第二次尝试
class ActiveStorage::Attachment < ActiveRecord::Base
attr_accessor :url
end
顺便说一句,在这两种情况下,它都加载了以下内容:
配置/初始化程序/monkey_patches.rb
require 'ext/active_storage/attachment'
因此,当它工作时,我没有错误消息,但过了一会儿补丁“消失”(缺乏更好的术语),我收到以下错误,告诉我我的 attr_accessor 不再存在。 Rails 必须重新加载 ActiveStorage 类,而我的补丁丢失了。
Module::DelegationError in Products#images
url delegated to blob, but blob is nil