gpt4 book ai didi

ruby-on-rails-4 - 从 Rails 3 升级到 Rails 4 后,CarrierWave url 为零

转载 作者:行者123 更新时间:2023-12-04 06:55:06 25 4
gpt4 key购买 nike

在将我们的应用程序从 Rails 3.2.22 升级到 Rails 4.2.11 时,升级之前工作的几个 CarrierWave 方法现在返回 nil,例如 .url.file .我们将 Assets 托管在 AWS S3 上,我们的应用程序托管在 Heroku 上。奇怪的是,图像在我们的开发环境中按预期工作。
CarrierWave 1.3.1 (upgraded from 0.11.2)Rails 4.2.11, upgraded from 3.2.22Ruby 2.2.5fog-aws 3.3.0
到目前为止,我已经尝试改变了载波配置,并在 rails 控制台中尝试了不同的方法,并将开发和生产中的结果进行了比较。

Gemfile

source 'https://rubygems.org'
ruby '2.2.5'

gem 'rails', '4.2.11'

gem 'puma'
gem 'pg', '0.15.1'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'rack-cors'
gem 'sprockets_uglifier_with_source_maps'
gem 'carrierwave'
gem 'mini_magick', '3.6.0'
gem 'paper_trail', '>= 4.0'
gem 'fog-aws'
gem 'aws-sdk-s3', '~> 1'
gem 'identity_cache', '>= 0.2'
gem 'memcachier'
gem 'dalli'
gem 'connection_pool'
gem 'active_model_serializers', '>= 0.10'
gem 'formtastic', '~> 3.1.0'
gem 'sprockets-rails', require: 'sprockets/railtie'
gem 'sprockets-image_compressor'
gem 'actionpack-action_caching'
gem 'sass-rails', '5.0.6'
gem 'uglifier', '2.5.0'
gem 'compass-rails'
gem 'sprite-factory', '1.5.3'
gem 'responders', '~> 2.0'

group :development do
gem 'rack-mini-profiler'
gem 'rmagick', '2.13.2'
end

carrierwave.rb


CarrierWave.configure do |config|
config.fog_provider = 'fog/aws'
config.fog_credentials = {
provider: ENV['FOG_PROVIDER'],
aws_access_key_id: ENV['AWS_ACCESS_KEY_ID'],
aws_secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
region: ENV['FOG_REGION'],
endpoint: ENV['FOG_HOST']
}
if Rails.env.production?
config.storage = :fog
config.fog_directory = ENV['FOG_DIRECTORY']
config.fog_public = false
config.fog_authenticated_url_expiration = 1800
else
config.asset_host = "#{ENV['FOG_HOST']}"
config.storage = :file
config.enable_processing = false if Rails.env.test?
end
end
art_uploader.rb

# encoding: utf-8

class ArtUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick

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

# 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}"
end

# Add a white list of extensions which are allowed to be uploaded.
def extension_white_list
%w(jpg jpeg png)
end

# Provide a default URL as a default if there hasn't been a file uploaded:
def default_url
if model.has_fallback_art?
version_name == :thumbnail
model.song.artist.photo.small_thumb.url :
model.song.artist.photo.album_art.url
end
end

end

我希望在进入时能够从 S3 返回 Assets 路径 art.url
在开发中我得到 art.url => "https://qa-marmosetmusic-com.s3.amazonaws.com/uploads/artist/photo/173/af2ac015-1d44-4481-b5d6-5bf5cb8c0e23.jpg"
然而在生产中 art.url => nil .

当我输入 art在开发控制台中,它返回这个对象:
=> #<ArtUploader::Uploader70128841541160:0x007f904c7c88f8
@cache_id=nil,
@file=
#<CarrierWave::SanitizedFile:0x007f904c1ffd68
@content=nil,
@content_type=nil,
@file=
"/Users/ekingan/dev/marmoset/public/uploads/album/art/3540/thumbnail_Evan_Andree_Your_Heart_Album_Artwork_1_3000x3000.jpg",
@original_filename=nil>,
@filename=nil,
@format=nil,
@model=
#<Album:0x007f904a0417a8
id: 3540,
title: "Your Heart",
art: "Evan_Andree_Your_Heart_Album_Artwork_1_3000x3000.jpg",
state: "active",
description: "",
created_at: Tue, 27 Nov 2018 12:50:14 PST -08:00,
updated_at: Tue, 27 Nov 2018 12:50:14 PST -08:00>,
@mounted_as=:art,
@parent_version=
#<ArtUploader:0x007f904c7c9618
@cache_id=nil,
@file=
#<CarrierWave::SanitizedFile:0x007f904c7c8948
@content=nil,
@content_type=nil,
@file="/Users/ekingan/dev/marmoset/public/uploads/album/art/3540/Evan_Andree_Your_Heart_Album_Artwork_1_3000x3000.jpg",
@original_filename=nil>,
@filename=nil,
@format=nil,
@model=
#<Album:0x007f904a0417a8
id: 3540,
title: "Your Heart",
art: "Evan_Andree_Your_Heart_Album_Artwork_1_3000x3000.jpg",
state: "active",
description: "",
created_at: Tue, 27 Nov 2018 12:50:14 PST -08:00,
updated_at: Tue, 27 Nov 2018 12:50:14 PST -08:00>,
@mounted_as=:art,
@storage=#<CarrierWave::Storage::File:0x007f904c7c9118 @cache_called=nil, @uploader=#<ArtUploader:0x007f904c7c9618 ...>>,
@versions={:thumbnail=>#<ArtUploader::Uploader70128841541160:0x007f904c7c88f8 ...>}>,
@storage=
#<CarrierWave::Storage::File:0x007f904c7c86f0
@cache_called=nil,
@uploader=#<ArtUploader::Uploader70128841541160:0x007f904c7c88f8 ...>>,
@versions={}>

当我在生产中输入相同的内容时,它会返回:
#<ArtUploader::Uploader6168740:0x000000072781c8 @model=#<Album id: 2008, title: "Vektlaus", art: "Daniel+Kvammen+-+Vektlaus.jpg", state: "active", description: nil, created_at: "2017-05-19 18:40:43", updated_at: "2017-07-26 16:51:17">, @mounted_as=:art, @file=nil, @filename=nil, @cache_id=nil, @versions={}, @format=nil, @parent_version=#<ArtUploader:0x00000007278d30 @model=#<Album id: 2008, title: "Vektlaus", art: "Daniel+Kvammen+-+Vektlaus.jpg", state: "active", description: nil, created_at: "2017-05-19 18:40:43", updated_at: "2017-07-26 16:51:17">, @mounted_as=:art, @file=nil, @filename=nil, @cache_id=nil, @versions={:thumbnail=>#<ArtUploader::Uploader6168740:0x000000072781c8 ...>}, @format=nil, @storage=#<CarrierWave::Storage::Fog:0x000000072786f0 @uploader=#<ArtUploader:0x00000007278d30 ...>>>, @storage=#<CarrierWave::Storage::Fog:0x00000007267300 @uploader=#<ArtUploader::Uploader6168740:0x000000072781c8 ...>>>

我很想听听任何建议。
谢谢!

最佳答案

我们解决了这个问题!

我们在carrierwave/storage中有一个名为fog.rb的文件,它覆盖了gem行为并导致了这个问题。删除该文件允许一切按预期工作。

关于ruby-on-rails-4 - 从 Rails 3 升级到 Rails 4 后,CarrierWave url 为零,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54355872/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com