Ruby on rails Rails ActiveStorage错误-MessageVerifier InvalidSignature
我正在做一个需要Ruby on rails Rails ActiveStorage错误-MessageVerifier InvalidSignature,ruby-on-rails,ruby,rails-activestorage,Ruby On Rails,Ruby,Rails Activestorage,我正在做一个需要ActiveStorage的项目,它附带了很多附件:照片位置模型上的情况 我在下面设置了代码,但在尝试上载表单时,我收到以下错误: ActiveSupport::MessageVerifier::InvalidSignature in LocationsController#attach_photo 这是将文件“添加”到特定父记录(即位置记录)的附件集中的方法吗 位置型号 类位置“234545”、“许可证号码”
ActiveStorage
的项目,它附带了很多附件:照片位置模型上的情况
我在下面设置了代码,但在尝试上载表单时,我收到以下错误:
ActiveSupport::MessageVerifier::InvalidSignature in
LocationsController#attach_photo
这是将文件“添加”到特定父记录(即位置
记录)的附件集中的方法吗
位置
型号
类位置
位置控制器
类位置控制器
看法
您需要将签名(在参数[:signed\u blob\u id]
中)分配给实例,如中的示例所示
那么像这样,
@location.photos.attach(params[:signed_blob_id]) # Signed reference to blob from direct upload
确保在表单标签中添加多部分:true
。它生成enctype=“多部分/表单数据”
form_标签
默认情况下不负责,必须拥有它(如果附加文件)
多部分/表单数据未编码任何字符。此值是必需的
使用具有文件上载控件的窗体时
表格:
<%= form_tag attach_photo_location_path(@location), method: :put, multipart: true do %>
<%= label_tag :photo %>
<%= file_field_tag :photo %>
<%= submit_tag "Upload" %>
<% end %>
启用网络检查的Rails活动存储+反应本机+反应本机调试器可能会导致此错误。
如果您在启用网络检查的情况下使用
,文件上载可能无法工作,因为存在以下已知问题:
使用React Native debugger时,请关闭网络检查。您可以改为使用Reactotron检查网络有效负载。我使用此方法解决了此问题
def用户参数
许可证(
:id,:name,:email,:username,:country,:avatar,:id\u number,:license\u number
).选择{x,v{v.present?}
结束
看起来空值导致了问题“avatar”=>“”
“身份证号码”=>“234545”、“许可证号码”=>“234545”、“化身”=>“
我的模型
class用户
我最近使用了ActiveStorage的直接上传功能。我喜欢这种方法的地方在于,我不需要编写任何代码来处理实际的上传本身,Rails为我做了这件事。你也采取这种方法了吗?请参阅此处的相关指南并让我知道:–尽管文档提到了上传到云,但它也适用于本地存储的文件。
<%= form_tag attach_photo_location_path(@location), method: :put, multipart: true do %>
<%= label_tag :photo %>
<%= file_field_tag :photo %>
<%= submit_tag "Upload" %>
<% end %>
resources :locations do
member do
put :attach_photo
end
end