Errno :: ENOENT in UsersController #index carrierwave

时间:2018-01-16 18:47:28

标签: ruby-on-rails ruby-on-rails-5 carrierwave

我在我的网站上遇到了一些问题,无法找到解决方法,

它有关于载波的事情,它之前工作正常,所以不确定发生了什么。

我已经更新了我安装的两个上传器,并且我也重新安装了宝石。

在存储图像的公共文件夹中有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

由于

1 个答案:

答案 0 :(得分:2)

在项目中创建一个目录,如:

public/uploads/cover/picture/47

并将名称为horse.jpg的图片粘贴到此文件夹的旁边 并再次运行, 你的问题只是因为你的公共图像目录不存在。