Skip to content

Commit

Permalink
#remove_previous fails to detect equality when mount_on option is set
Browse files Browse the repository at this point in the history
  • Loading branch information
mshibuya committed Aug 12, 2016
1 parent 30c6dfd commit 44cfb7c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/carrierwave/mounter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def serialization_column
def remove_previous(before=nil, after=nil)
return unless before

# both 'before' and 'after' can be string when 'mount_on' option is set
before = before.reject(&:blank?).map do |value|
if value.is_a?(String)
uploader = blank_uploader
Expand All @@ -133,7 +134,15 @@ def remove_previous(before=nil, after=nil)
value
end
end
after_paths = Array(after).reject(&:blank?).map { |value| value.try(:path) || value }
after_paths = after.reject(&:blank?).map do |value|
if value.is_a?(String)
uploader = blank_uploader
uploader.retrieve_from_store!(value)
uploader
else
value
end.path
end
before.each do |uploader|
if uploader.remove_previously_stored_files_after_update and not after_paths.include?(uploader.path)
uploader.remove!
Expand Down

1 comment on commit 44cfb7c

@toshimaru
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

Please sign in to comment.