I'm having problems setting the default image in my carrier-supported bootloader. It seems to add a weird class to the top of the url, but it doesn't create an image. See my code below.
Assistant
class UserpicUploader < CarrierWave::Uploader::Base
CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/
include CarrierWave::RMagick
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :normal do
process :resize_to_fill => [162, 163]
end
def default_url
"/images/fallback/" + [normal, "profile_default_pic.png"].compact.join('_')
end
def extension_white_list
%w(jpg jpeg gif png)
end
def filename
if original_filename
@name ||= Digest::MD5.hexdigest(File.dirname(current_path))
"#{@name}.#{file.extension}"
end
end
end
EDIT ...
Here is the edited code that worked. I had to put the image in open / backup, and not in Assets / images / fallback.
class UserpicUploader < CarrierWave::Uploader::Base
CarrierWave::SanitizedFile.sanitize_regexp = /[^[:word:]\.\-\+]/
include CarrierWave::RMagick
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
storage :file
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :normal do
process :resize_to_fill => [162, 163]
end
def default_url
asset_path("fallback/" + [normal, "profile_default_pic.png"].compact.join('_'))
end
def extension_white_list
%w(jpg jpeg gif png)
end
def filename
if original_filename
@name ||= Digest::MD5.hexdigest(File.dirname(current_path))
"#{@name}.#{file.extension}"
end
end
end
Daveg source
share