我正在处理一个项目,需要在Location
模型上使用ActiveStorage
的has_many_attached :photos
。
我已经设置了下面的代码,但在尝试上传表单时,我收到以下错误:
ActiveSupport::MessageVerifier::InvalidSignature in
LocationsController#attach_photo
这是将文件“添加”到特定父记录(即记录)的附件集中的方法吗?
Location
模型
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