在生产中上传图像并暂存Carrierwave,fog和S3时,资产未编译错误

时间:2016-03-30 11:00:12

标签: ruby-on-rails amazon-s3 carrierwave fog

出于某种原因,我无法在生产/登台环境中上传图像,一切都在开发中运行良好。我试图在制作中上传图片时得到Sprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError: isn't precompiled。任何帮助将不胜感激。

这是(gist)日志输出

# Carrierwave.rb

require 'fog/aws'

CarrierWave.configure do |config|
    config.fog_credentials = {
        provider:                 'AWS',
        aws_access_key_id:          ENV['AWS_ACCESS_KEY_ID'],
        aws_secret_access_key:  ENV['AWS_SECRET_ACCESS_KEY'],
        region:                                 'us-east-1'
    }
    config.fog_directory = ENV['S3_BUCKET_NAME']
    config.fog_public    = true
    # config.ignore_integrity_errors = false
    # config.ignore_processing_errors = false
end


# Ref:
# https://support.cloud.engineyard.com/entries/20996881-Use-CarrierWave-and-Optionally-Fog-to-Upload-and-Store-Files#update3
# http://stackoverflow.com/questions/7946819/carrierwave-and-amazon-s3

=============================
# AvatarUploader.rb

# encoding: utf-8

class AvatarUploader < CarrierWave::Uploader::Base

  # Include RMagick or MiniMagick support:
  # include CarrierWave::RMagick
  include CarrierWave::MiniMagick

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

  # Override the directory where uploaded files will be stored.
  # This is a sensible default for uploaders that are meant to be mounted:
  def store_dir
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
    # "tmp/#{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
  #   # For Rails 3.1+ asset pipeline compatibility:
  #   # ActionController::Base.helpers.asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
  #
  #   "/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

  process :resize_to_fill => [150, 150]

  version :inner do
    process resize_to_fill: [100, 100]
  end

  version :profile, from_version: :inner do
    process resize_to_fill: [45, 45]
  end

  version :small, from_version: :profile do
    process resize_to_fill: [30, 30]
  end

  version :tiny, form_version: :small do
    process resize_to_fill: [20, 20]
  end

  # Create different versions of your uploaded files:
  # version :thumb do
  #   process :resize_to_fit => [50, 50]
  # 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
  #   "#{expert.email}.jpg" if original_filename
  # end

end

1 个答案:

答案 0 :(得分:0)

似乎资产没有预编译。这个问题似乎与CarrierWave无关。运行RAILS_ENV =生产包exec rake资产:预编译