拜托,你能看看我的配置吗?我正在尝试在我的应用程序中设置carrierwave,但它在生产服务器中不起作用。它甚至可以作为生产环境在本地工作。问题是它将图像保存到 tmp 目录中,但结果是“空文件上传结果”。我尝试保存到文件并保存到 S3,结果相同。我正在使用乘客 - Nginx。
这两天我都生气了。任何关于如何调试的想法或提示都是受欢迎的。我设置了所有权限,所以我认为这不是权限问题。它可能是缓存的东西,文件存储在 tmp 目录中,但似乎应用程序不认为它们归用户所有???
谢谢!!!
#application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
if defined?(Bundler)
Bundler.require(*Rails.groups(:assets => %w(development test)))
end
module MyApp
class Application < Rails::Application
config.encoding = "utf-8"
config.filter_parameters += [:password]
config.active_support.escape_html_entities_in_json = true
config.active_record.whitelist_attributes = true
config.assets.initialize_on_precompile = false
config.assets.enabled = true
config.assets.version = '1.0'
end
end
# avatar_uploader.rb
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
include ActiveModel::Conversion
extend ActiveModel::Naming
def extension_white_list
%w(jpg jpeg gif png mp3)
end
include Sprockets::Helpers::RailsHelper
include Sprockets::Helpers::IsolatedHelper
storage :fog
def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
version :thumb do
process :resize_to_fill => [200,200]
end
end
# carrierwave.rb
CarrierWave.configure do |config|
config.fog_credentials = {
:provider => 'AWS', # required
:aws_access_key_id => 'ACCESS', # required
:aws_secret_access_key => 'SECRET', # required
:region => 'eu-west-1' # optional, defaults to 'us-east-1'
}
config.fog_directory = 'my_app_bucket'
end
# production.rb
MyApp::Application.configure do
config.cache_classes = true
config.consider_all_requests_local = true # default false, debug true
config.action_controller.perform_caching = true #default true
config.serve_static_assets = true # Carrierwave true - Default false
config.assets.compress = true
config.assets.compile = false # false for real production
config.assets.digest = true
config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
config.log_level = :debug
config.cache_store = :dalli_store
config.assets.precompile += %w( search.js )
config.i18n.fallbacks = true
config.active_support.deprecation = :notify
config.action_mailer.default_url_options = { :host => 'localhost' }
end