何らかの原因で、プロダクション/ステージング環境で画像をアップロードできません。プロダクションで写真をアップロードしようとすると、私はSprockets::Helpers::RailsHelper::AssetPaths::AssetNotPrecompiledError: isn't precompiled
を取得します。どんな助けでも大歓迎です。ここでプロダクションとステージングで画像をアップロードしてCarrierwave、Fog、S3をステージングするときに、アセットがコンパイルされないエラー
は、資産がプリコンパイルされていないようです(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
実動環境またはステージング環境でアセットをプリコンパイルしようとしましたか? 'RAILS_ENV = production bundle exec rake assets:precompile'コマンドを使って本番環境でこれを行うことができます。 – dp7
アップロード時にこのエラーが発生していますが、後でビューでアバターを使用したときにエラーが発生していませんか? –
@ dkp、yepはそれを試しましたが、同じエラーが発生しました – intercoder