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