Created
August 9, 2012 13:54
-
-
Save rlivsey/3304402 to your computer and use it in GitHub Desktop.
CarrierWave why u ignore inheritance in versions?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Were you able to get this work?