【问题标题】:Cannot access the pictures uploaded by Carrierwave versions in production environment生产环境下无法访问Carrierwave版本上传的图片
【发布时间】:2014-10-24 02:27:21
【问题描述】:

这是我的上传者:

class PhotoUploader < CarrierWave::Uploader::Base

  include CarrierWave::MiniMagick
  process :resize_to_fit => [nil, 600]

  version :thumb do
    process :resize_to_fill => [150,150]
  end

  # Choose what kind of storage to use for this uploader:
  storage :file

  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
  end

  def cache_dir
    "#{Rails.root}/tmp/uploads"
  end

  def extension_white_list
    %w(jpg jpeg gif png)
  end

  def filename
    if original_filename
      @name ||= Digest::MD5.hexdigest(current_path)
      "#{@name}.#{file.extension}"
    end
  end

end

production.rb中,我设置了config.serve_static_assets = false

然后我使用 Capistrano 在生产服务器(Nginx + Passenger)上部署了这个项目。当我上传图片时,它会在/home/deploy/Gallary/current/public/uploads/picture/photo/目录下生成2份,如下图所示:

我可以通过浏览器访问第一个(因为这个是Carrierwave生成的默认文件),而第二个(由version :thumb生成)抛出一个异常,如下所示:

ActionController::RoutingError (No route matches [GET] "/uploads/picture/photo/49/thumb_6d9596c7449d3714eadb74b9c71beec2.jpg")

实际上这个文件thumb_6d9596c7449d3714eadb74b9c71beec2.jpg确实存在于那里的dic中。

那么,怎么了?我该怎么办?

【问题讨论】:

    标签: ruby-on-rails nginx carrierwave production


    【解决方案1】:

    我遇到了类似的问题。在另一个线程中找到了答案。 所以试试这个:

    Server unable to find public folder in rails 3 production environment

    为我工作

    【讨论】:

    • 我想我已经解决了这个问题多年,但我想我现在不记得解决方案了。顺便说一句,你上面提到的方法对我不起作用。
    猜你喜欢
    • 1970-01-01
    • 2015-05-17
    • 1970-01-01
    • 2020-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    相关资源
    最近更新 更多