【发布时间】:2018-01-16 18:47:28
【问题描述】:
我的网站遇到了一些问题,无法找到解决方案,
它与载波有关,之前它工作正常,所以不确定发生了什么。
我已经更新了我已经安装的两个上传器,并且我也重新安装了 gem。
在图像存储在 1 个图像中的公共文件夹中,但是当我执行 Cover.count 时,它显示为 11
Cover.destroy_all
Errno::ENOENT: No such file or directory @ rb_sysopen - /Users/nyall/Desktop/touchthisup/public/uploads/cover/picture/47/horse.jpg
from app/uploaders/cover_uploader.rb:41:in `is_landscape?'
from (irb):3
这是我的上传者:
class CoverUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
storage :file
# storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
process resize_to_fit: [900, 900]
version :landscape, if: :is_landscape? do
process resize_to_fit: [@land_height, 250]
end
version :portrait, if: :is_portrait? do
process resize_to_fit: [250, @port_width]
end
process :store_dimensions
def extension_whitelist
%w(jpg jpeg png)
end
def content_type_whitelist
/image\//
end
private
def store_dimensions
if file && model
model.width, model.height = ::MiniMagick::Image.open(file.file)[:dimensions]
end
end
def is_landscape? picture
image = MiniMagick::Image.open(picture.path)
width = image[:width]
aspect = image[:width] / image[:height].to_f
@land_height = aspect * width
image[:width] > image[:height]
end
def is_portrait? picture
image = MiniMagick::Image.open(picture.path)
height = image[:height]
aspect = image[:width] / image[:height].to_f
@port_width = height / aspect
image[:width] < image[:height]
end
end
谢谢
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-5 carrierwave