Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In a multiple file upload I seem not to be able to delete the last file properly. #2010

Closed
Lubmes opened this issue Aug 27, 2016 · 2 comments

Comments

@Lubmes
Copy link

Lubmes commented Aug 27, 2016

Using your wiki https://github.com/carrierwaveuploader/carrierwave/wiki/How-to:-Add-more-files-and-remove-single-file-when-using-default-multiple-file-uploads-feature

I used the corresponding controller, but in my case for .stl files.

class ImagesController < ApplicationController
  before_action :set_gallery

  def create
    add_more_images(images_params[:images])
    flash[:error] = "Failed uploading images" unless @gallery.save
    redirect_to :back
  end

  def destroy
    remove_image_at_index(params[:id].to_i)
    flash[:error] = "Failed deleting image" unless @gallery.save
    redirect_to :back
  end

  private

  def set_gallery
    @gallery = Gallery.find(params[:gallery_id])
  end

  def add_more_images(new_images)
    images = @gallery.images 
    images += new_images
    @gallery.images = images
  end

  def remove_image_at_index(index)
    remain_images = @gallery.images # copy the array
    deleted_image = remain_images.delete_at(index) # delete the target image
    deleted_image.try(:remove!) # delete image from S3
    @gallery.images = remain_images # re-assign back
  end

  def images_params
    params.require(:gallery).permit({images: []}) # allow nested params as array
  end
end

I seem to not be able to correctly remove the very last file. In my printed file list it keeps on standing there. Oddly enough with 0kb.

Only when I load up new files this one does go away.

RSpec says:

Users can edit factory by removing a project file
Failure/Error: expect(page).to_not have_content 'the_puritan_1st_floor.stl'
expected not to find text "the_puritan_1st_floor.stl" in " (...) Project Files: the_puritan_1st_floor.stl (0 bytes) Edit Factory"

In my view I can clearly see that clicking delete on a list of stl files does work, but when reloading this strange 0kb file keeps popping up.

@jcarlos
Copy link

jcarlos commented Sep 6, 2016

See #1990

@mshibuya
Copy link
Member

mshibuya commented May 1, 2019

Merging into #1990.

@mshibuya mshibuya closed this as completed May 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants