为了使用 Active Storage 将图像文件导入 Rails 应用程序,我编写了这样的 Rake:
task :import_file => :environment do
path = Rails.root.join("tmp", "sample.jpg")
data = File.read(path)
post = Post.first
post.image.attach(data)
end
当我执行这个任务时,我得到了一个 Exception ActiveSupport::MessageVerifier::InvalidSignature
。
我怎样才能避免这个错误?
模型源代码Post
为:
class Post < ApplicationRecord
has_one_attached :image
end
我使用默认的config/storage.yml
.
test:
service: Disk
root: <%= Rails.root.join("tmp/storage") %>
local:
service: Disk
root: <%= Rails.root.join("storage") %>
Rails 的版本是 5.2.0.beta2。