Errno::ENOENT 在 UsersController#index carrierwave

Errno::ENOENT in UsersController#index carrierwave

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

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

我更新了我安装的两个上传器,我也重新安装了 gem。

在 public 文件夹中,图像以 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

谢谢

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

public/uploads/cover/picture/47

并将名称为 horse.jpg 的图像粘贴到此文件夹中 运行 再试一次, 你的问题只是因为你的 public 图片目录不对。