【发布时间】:2014-12-12 18:35:56
【问题描述】:
我上传的图片按预期工作,除非我向 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 的目的是让用户从他们的手机上传图片,图片是自动定向的。此当前代码适用于移动上传的图像,但是当我尝试从桌面上的网络应用程序上传图像时,我收到:“未定义的方法 `destroy!'为真:TrueClass”。
我查看了documentationfor minimagick 并考虑将 auto_orient 更改为 auto_orient!但后来我被告知 minimagick 没有名为 auto_orient 的方法!为什么用这个方法调用destroy?
【问题讨论】:
-
检查auto_orient方法返回true还是object。主要是用 !返回真或假。尝试替换操作方法而不是操作!。
-
显然,对于carrierwave 模块,没有auto_orient 方法(没有!)。看文档,好像是返回了img。
-
@Tommyixi 在你的问题中,你用相反的方式写它。哪个是对的?
-
@PatrickOscity 对不起,我的意思是说没有操纵方法,只有操纵!
标签: ruby-on-rails ruby ruby-on-rails-4 minimagick