Skip to content

Instantly share code, notes, and snippets.

@mitsuru
Last active August 29, 2015 14:23
Show Gist options
  • Save mitsuru/386c974c934026faa57b to your computer and use it in GitHub Desktop.
Save mitsuru/386c974c934026faa57b to your computer and use it in GitHub Desktop.
paper_trailでCarrierWaveのフィールドのファイル名のみを保存する
module PaperTrail
module Model
module InstanceMethods
private
def item_before_change
attributes.tap do |prev|
enums = self.respond_to?(:defined_enums) ? self.defined_enums : {}
changed_attributes.select { |k,v| self.class.column_names.include?(k) }.each do |attr, before|
before = enums[attr][before] if enums[attr]
if defined?(CarrierWave::Uploader::Base) && before.is_a?(CarrierWave::Uploader::Base)
prev[attr] = (before.url && File.basename(before.url))
else
prev[attr] = before
end
end
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment