簡體   English   中英

Rails 5.2 Active Storage 不刪除附加的圖像

[英]Rails 5.2 Active Storage not deleting attached images

我正在嘗試刪除附加到招聘信息的圖片。 但是點擊刪除后,附加的圖像仍然存在並且不會從職位發布中刪除。

工作展示頁面

<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

作業控制器.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?' } %>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM