ruby-on-rails – Active Storage引发ActiveSupport :: MessageV
发布时间:2020-12-17 03:07:58 所属栏目:百科 来源:网络整理
导读:要使用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 当我执行此任务时,我
要使用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. 解决方法
在
Edge API document,我找到了答案.
desc "Import file" task :import_file => :environment do path = Rails.root.join("tmp","sample.jpg") post = Post.first File.open(path) do |io| post.image.attach(io: io,filename: "sample.jpg") end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |