Try this
User.new.avatar.versions.keys
CarrierWave::Uploader#versions
returns a Hash
with the version name as key and the corresponding URL as the value.
Domanda
Let's say I have an uploader for avatars with two sizes defined.
class AvatarUploader < ApplicationUploader
include CarrierWave::MiniMagick
def default_url
"/images/placeholder_#{version_name}.png"
end
process resize_to_fill: [200, 200]
version :large_thumb do
process resize_to_fill: [78, 78]
end
version :small_thumb do
process resize_to_fill: [33, 33]
end
def extension_white_list
%w(jpg jpeg gif png)
end
end
Is there a way to get all the available size in an array or hash?
In the best case scenario - that some sort of method would return:
User.new.avatar.available_sizes = [:large_thumb, :small_thumb]
Soluzione
Try this
User.new.avatar.versions.keys
CarrierWave::Uploader#versions
returns a Hash
with the version name as key and the corresponding URL as the value.