Skip to content

Commit

Permalink
Prevent storing _old_ when nil is passed
Browse files Browse the repository at this point in the history
  • Loading branch information
simonc committed Apr 27, 2022
1 parent 506a6fb commit 8b1d12f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/carrierwave/mongoid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def #{column}=(new_file)
@_previous_uploader_value_for_#{column} = previous_uploader_value
# mongoid won't upload a new file if there was no file previously.
write_uploader(column, '_old_') if self.persisted? && read_uploader(column).nil?
if self.persisted? && read_uploader(column).nil? && !new_file.path.nil?
write_uploader(column, '_old_')
end
send(:"\#{column}_will_change!")
super
Expand Down

0 comments on commit 8b1d12f

Please sign in to comment.