"git://github.com/jnicklas/carrie-6ren">
gpt4 book ai didi

ruby-on-rails - 不是公认的存储提供商(Mongoid、Carrierwave 和 S3

转载 作者:行者123 更新时间:2023-12-01 21:50:42 25 4
gpt4 key购买 nike

我正在使用带有 mongoid 支持的 Carrierwave

gem "carrierwave-mongoid", :git => "git://github.com/jnicklas/carrierwave-mongoid.git", :branch => "mongoid-3.0",:require => 'carrierwave/mongoid'

我将 Carrierwave 配置为将雾存储与 AWS (S3) 结合使用

# config/initializers/carrierwave.rb
CarrierWave.configure do |config|
config.storage = :fog
config.root = Rails.root.join('tmp') # adding these...
config.cache_dir = 'carrierwave' # ...two lines
config.fog_credentials = {
:provider => 'AWS',
:aws_access_key_id => '',
:aws_secret_access_key => ''
},
config.fog_directory = 'alzheimer'
end

我有一个名为 Picture 的类,用于与 uploader 和 uploader 一起使用

class ImagenUploader < CarrierWave::Uploader::Base
include CarrierWave::MimeTypes
include CarrierWave::RMagick
storage :fog
process :set_content_type
process :convert => 'png'
def filename
super.chomp(File.extname(super))+'.png'
end
version :thumb do
process :resize_to_fit => [24,24]
end
end

还有我的图片模型 类(class)图片 包括 Mongoid::文档 包括 Mongoid::时间戳 包括 Mongoid::偏执狂 属于:用户

     field :descripcion, :type => String
field :titulo, :type => String
field :imagen, :type => String

attr_accessible :imagen, :imagen_cache, :descripcion, :titulo
mount_uploader :imagen, ImagenUploader
end

我尝试上传图片,但我得到:

ArgumentError: is not a recognized storage provider
from /Users/msdark/.rvm/gems/ruby-1.9.3-p194/gems/fog-1.5.0/lib/fog/storage.rb:33:in new'
from /Users/msdark/.rvm/gems/ruby-1.9.3-p194/gems/carrierwave-0.6.2/lib/carrierwave/storage/fog.rb:106:inconnection'

我使用rails 3.2.8 ruby 1.9.3p194和 unicorn (4.3.1)

上传后尝试显示此错误时显示错误:

image_tag(picture.imagen_url)

有什么想法吗?

编辑:

gem 文件

source 'https://rubygems.org'
gem 'rails', '3.2.8'
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'therubyracer', :platform => :ruby
gem 'uglifier', '>= 1.0.3'
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'less-rails-bootstrap'
end

gem 'unicorn'
gem 'heroku'
gem 'foreman'

gem 'i18n'
gem 'formtastic'
gem "activeadmin-mongoid", git: "git://github.com/elia/activeadmin-mongoid.git"
gem 'mongoid'
gem 'bson_ext'
gem 'devise'
gem 'devise-i18n'
gem 'omniauth'
gem 'omniauth-twitter'
gem 'omniauth-facebook'

gem "carrierwave-mongoid", :git => "git://github.com/jnicklas/carrierwave-mongoid.git", :branch => "mongoid-3.0", :require => 'carrierwave/mongoid'
gem 'mini_magick', :git => 'git://github.com/probablycorey/mini_magick.git'

gem 'recaptcha', :require => 'recaptcha/rails'
gem 'googlecharts'

group :test do
gem 'capybara'
gem 'database_cleaner'
gem 'mongoid-rspec'
gem 'launchy'
gem 'factory_girl_rails'
gem 'mongoid-rspec'
gem 'faker'
end
gem 'rspec-rails',:group =>[:development,:test]

最佳答案

我也遇到了类似的问题。事实证明,我的 uploader 没有与配置中定义的存储引擎相匹配。我在 Carrierwave 配置内部进行了 pry 动(在初始化程序中)并查看了 storage_engines。

[5] pry(main)> config.storage_engines
=> {:file=>"CarrierWave::Storage::File", :fog=>"CarrierWave::Storage::Fog"}

然后我确保上传者的设置与此处的条目之一匹配。所以就你而言,如果你有

class ImagenUploader < CarrierWave::Uploader::Base
...
storage :fog
...
end

那么您需要确保您使用的配置上下文中存在 :fog 条目。您可以从那里原路返回。

我意识到这是一个稍微老的问题,但如果您还没有弄清楚,我希望这会有所帮助。

关于ruby-on-rails - 不是公认的存储提供商(Mongoid、Carrierwave 和 S3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12379890/

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