Skip to content

Instantly share code, notes, and snippets.

@rlivsey
Created August 9, 2012 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rlivsey/3304402 to your computer and use it in GitHub Desktop.
Save rlivsey/3304402 to your computer and use it in GitHub Desktop.
CarrierWave why u ignore inheritance in versions?
# CarrierWave versions are created with Class.new(self) in the class they're defined in:
# https://github.com/jnicklas/carrierwave/blob/master/lib/carrierwave/uploader/versions.rb#L54
# That means if you inherit an uploader and want to do something different, such as change
# the directory files are stored in, you're out of luck.
class BaseUploader < CarrierWave::Uploader::Base
def store_dir
"base/dir"
end
version :normal do
process :resize_to_fill => [100, 100]
end
end
class ChildUploader < BaseUploader
def store_dir
"child/dir"
end
version :custom do
process :resize_to_fill => [200, 200]
end
end
uploader = ChildUploader.new
puts uploader.store_dir
# "child/dir"
# all good, as we'd expect
puts uploader.custom.store_dir
# "child/dir"
# still good
puts uploader.normal.store_dir
# "base/dir"
# Boom!
@niyando
Copy link

niyando commented Feb 11, 2015

Were you able to get this work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment