Rails 5.2 Active Storage 不删除附加图像
Rails 5.2 Active Storage not deleting attached images
我正在尝试删除附加到作业 post 的图像。但是在点击删除后,附加的图像仍然存在并且没有从作业中删除 post。
职位展示页面
<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>
路线
resources :jobs do
member do
delete :delete_image_attachment
end
end
jobs_controller.rb
def delete_image_attachment
@image = ActiveStorage::Blob.find_signed(params[:id])
@image.purge
redirect_to root_path
end
在我的控制器中,我将 @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
我现在的删除操作是:
<%= link_to 'Remove', delete_image_attachment_job_url(image),
method: :delete,
data: { confirm: 'Are you sure?' } %>
我正在尝试删除附加到作业 post 的图像。但是在点击删除后,附加的图像仍然存在并且没有从作业中删除 post。
职位展示页面
<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>
路线
resources :jobs do
member do
delete :delete_image_attachment
end
end
jobs_controller.rb
def delete_image_attachment
@image = ActiveStorage::Blob.find_signed(params[:id])
@image.purge
redirect_to root_path
end
在我的控制器中,我将 @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
我现在的删除操作是:
<%= link_to 'Remove', delete_image_attachment_job_url(image),
method: :delete,
data: { confirm: 'Are you sure?' } %>