【问题标题】:Errno::ENOENT in UsersController#index carrierwave用户控制器中的 Errno::ENOENT#index carrierwave
【发布时间】: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


    【解决方案1】:

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

    public/uploads/cover/picture/47
    

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

    【讨论】:

    • 谢谢你,你知道为什么会这样吗?
    • @johnseymour 不确定,但您错误地删除了此公用文件夹,并且当销毁操作试图删除此文件时,该文件不存在。这就是为什么你得到错误No such file or directory
    猜你喜欢
    • 1970-01-01
    • 2013-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-14
    相关资源
    最近更新 更多