Class: CarrierWave::Mounter
- Inherits:
-
Object
- Object
- CarrierWave::Mounter
- Defined in:
- lib/custom_fields/extensions/carrierwave.rb
Instance Method Summary collapse
- #remove_previous_with_localization(before = nil, after = nil) ⇒ Object (also: #remove_previous)
Instance Method Details
#remove_previous_with_localization(before = nil, after = nil) ⇒ Object Also known as: remove_previous
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/custom_fields/extensions/carrierwave.rb', line 7 def remove_previous_with_localization(before = nil, after = nil) _before = before _after = after locale = ::Mongoid::Fields::I18n.locale.to_s # custom case: # the record owns a localized file field. A new file has been attached to it # in the default locale. Now, we want to upload a file in another locale with # a different name. # We absolutely don't want to erase the file in the default locale if record.class.fields[column.to_s]&.localized? && record.changes[column]&.first == '_new_' _before = [nil] end # FIXME: can't reproduce this behavior locally but it happens in production _before = [before.first[locale]] if before && before.first.is_a?(Hash) _after = [after.first[locale]] if after && after.first.is_a?(Hash) remove_previous_without_localization(_before, _after) end |