我上传的图片按预期工作,除非我向ImageUploader添加了一个额外的进程(auto_orient)。代码如下:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
retina!
if Rails.env.development?
def store_dir
"#{Rails.root}/public/uploads/account_#{model.account_id}/product_#{model.product_id}/image_#{model.id}"
end
elsif Rails.env.staging? || Rails.env.production?
def store_dir
"uploads/account_#{model.account_id}/product_#{model.product_id}/image_#{model.id}"
end
end
def default_url
"/assets/no_image_500px.png"
end
process :auto_orient
process :resize_and_pad => [500, 500]
version :thumb_100 do
process :resize_and_pad => [100, 100]
end
version :shopping_cart do
process :resize_to_fill => [200, 200]
process :retina_quality => 100
end
version :store_page do
process :resize_to_fill => [336, 336]
process :retina_quality => 100
end
version :product_page do
process :resize_to_fill => [426, 426]
process :retina_quality => 100
end
def extension_white_list
%w(jpg jpeg png tiff)
end
def auto_orient
manipulate! do |img|
img = img.auto_orient
end
end
end
Auto_orient用于用户从手机上传图像,图像是自动定向的。这个当前代码适用于移动上传的图像,但当我尝试从桌面上的Web应用程序上传图像时,我收到:“未定义的方法`销毁!”为true:TrueClass“。
我查看了documentation的minimagick,并考虑将auto_orient更改为auto_orient!但后来我被告知minimagick没有名为auto_orient的方法!为什么用这种方法调用destroy?
答案 0 :(得分:3)
看起来像操纵!在auto_orient的返回时调用destroy方法(最终是一个布尔值(true))。因此无法在布尔值上调用delete的错误。为了解决这个问题,我添加了ruby&#34; tap&#34;将图像传递到块然后立即返回图像的方法:
def auto_orient
manipulate! do |img|
img.tap(&:auto_orient)
end
end
答案 1 :(得分:0)
回答你的问题也许为时已晚,但我有另一个答案,为了解决毁灭!麻烦你必须返回并img里面的操纵块
def auto_orient
manipulate! do |img|
img = img.auto_orient
img
end
end