[英]Rails 5.2 Active Storage not deleting attached images
I'm trying to delete an image that's attached to a job post.我正在尝试删除附加到招聘信息的图片。 But after clicking on remove, the attached image is still there and doesn't get deleted from the job post.
但是点击删除后,附加的图像仍然存在并且不会从职位发布中删除。
Job Show page工作展示页面
<div class="ui text container slides">
<i class=" left angle icon"></i>
<i class=" right angle icon"></i>
<% @job.images.each_with_index do |image, index| %>
<div class="slide active">
<%= image_tag image, size: 200 %>
<%= link_to 'Remove', delete_image_attachment_job_url(image.signed_id),
method: :delete,
data: { confirm: 'Are you sure?' } %>
</div>
<% end %>
</div>
</div>
routes路线
resources :jobs do
member do
delete :delete_image_attachment
end
end
jobs_controller.rb作业控制器.rb
def delete_image_attachment
@image = ActiveStorage::Blob.find_signed(params[:id])
@image.purge
redirect_to root_path
end
In my controller, i replaced @image = ActiveStorage::Blob.find_signed(params[:id])
with:在我的控制器中,我将
@image = ActiveStorage::Blob.find_signed(params[:id])
替换为:
def delete_image_attachment
@image = ActiveStorage::Attachment.find(params[:id])
@image.purge
redirect_back(fallback_location: job_path)
end
My delete action is now:我的删除操作现在是:
<%= link_to 'Remove', delete_image_attachment_job_url(image),
method: :delete,
data: { confirm: 'Are you sure?' } %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.