1

我正在使用 CarrierWave gem 上传图像。问题是,如果有人在浏览器中打开网络终端,他们可以很容易地找到图像的名称。所以我只想通过在部署到服务器时重命名图像文件来避免它。所以我可以使用文件名。但问题就在这里。“文件名”方法根本没有在我的代码中执行。这是我的上传文件。

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

  # Provide a default URL as a default if there hasn't been a file uploaded:
  # def default_url
  #   "/images/fallback/" + [version_name, "default.png"].compact.join('_')
  # end

  # Process files as they are uploaded:
  # process :scale => [200, 300]
  #
  # def scale(width, height)
  #   # do something
  # end

  # Create different versions of your uploaded files:
  version :thumb do
     process :resize_to_limit => [100, 100]
  end

  # Add a white list of extensions which are allowed to be uploaded.
  # For images you might use something like this:
  def extension_white_list
    %w(jpg jpeg gif png)
  end

  # Override the filename of the uploaded files:
  # Avoid using model.id or version_name here, see uploader/store.rb for details.
  # def filename
  #   "something.jpg" if original_filename
  # end
  def filename
    logger.info "*******inside filename method"
  end

end

提前致谢

4

0 回答 0