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

Skip removing old uploaded images when uploading new images #2288

Closed
Theopaps opened this issue Mar 5, 2018 · 2 comments
Closed

Skip removing old uploaded images when uploading new images #2288

Theopaps opened this issue Mar 5, 2018 · 2 comments

Comments

@Theopaps
Copy link

Theopaps commented Mar 5, 2018

I have implemented this
And when I upload new images the old ones get deleted. So I'm trying the following inside the model in order to bypass this, but without any luck. It's not working as well.

mount_uploaders :attachments, AttachmentUploader skip_callback :commit, :after, :remove_previously_stored_avatar, :on=> :update, raise: false

Any idea how I can upload new files and keep the old ones?

@ljuborados
Copy link

For anyone who might end up on this issue, I've done it like this:

class Rider < ActiveRecord::Base
  mount_uploaders :documents, RiderDocumentUploader

  def documents=(documents)
    docs_to_append = documents.map do |doc|
      uploader = RiderDocumentUploader.new(self)
      uploader.store! doc
      uploader
    end
    self[:documents] ||= []
    self[:documents] += docs_to_append.map {|uploader| uploader.file.filename}
  end
end

Not sure if this is the best way, but it works!

@mshibuya
Copy link
Member

Closed by #2401.

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