ruby-on-rails – Rails ActiveStorage错误 – MessageVerifier-
发布时间:2020-12-17 02:49:56 所属栏目:百科 来源:网络整理
导读:我正在开发一个需要ActiveStorage has_many_attached的项目:位置模型上的照片情况. 我在下面设置了代码,但在尝试上传表单时,收到以下错误: ActiveSupport::MessageVerifier::InvalidSignature in LocationsController#attach_photo 这是将文件“添加”到特
我正在开发一个需要ActiveStorage has_many_attached的项目:位置模型上的照片情况.
我在下面设置了代码,但在尝试上传表单时,收到以下错误: ActiveSupport::MessageVerifier::InvalidSignature in LocationsController#attach_photo 这是将文件“添加”到特定父记录的附件集(即:位置记录)的方法吗? 位置模型 class Location < ApplicationRecord ... has_many_attached :photos ... end 地点控制器 class LocationsController < ApplicationController ... def attach_photo @location = Location.find(params[:id]) @location.photos.attach(params[:photo]) redirect_to location_path(@location) end ... end 视图 <%= form_tag attach_photo_location_path(@location) do %> <%= label_tag :photo %> <%= file_field_tag :photo %> <%= submit_tag "Upload" %> <% end %> 视图 resources :locations do member do post :attach_photo end end 解决方法
确保在form_tag中添加multipart:true.它生成enctype =“multipart / form-data”.
form_tag默认不负责,必须拥有它(如果附加文件).
形成: <%= form_tag attach_photo_location_path(@location),method: :put,multipart: true do %> <%= label_tag :photo %> <%= file_field_tag :photo %> <%= submit_tag "Upload" %> <% end %> 也: 更改发布方法,我们正在更新不创建Idempotency resources :locations do member do put :attach_photo end end (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |