这是我的宝石列表,
我试图生成上传图片,但它不起作用,carrierwave.rb看起来像这样:
require 'carrierwave/mongoid'
CarrierWave.configure do |config|
config.grid_fs_database = Mongoid::Config.sessions[:default]
config.grid_fs_port = 27017
config.grid_fs_host = '127.0.0.1'
config.storage = :grid_fs
end
但是出错了:
/config/initializers/carrierwave.rb:3:in `block in <top (required)>': undefined method `grid_fs_database=' for CarrierWave::Uploader::Base:Class (NoMethodError)
.....
有一个解决方案吗?
感谢
答案 0 :(得分:0)
我快速查看the source for carrierwave-mongoid,您指定的配置选项(grid_fs_database
,grid_fs_port
和grid_fs_host
)似乎无效 - 因此,错误。
我的理解是carrierwave-mongoid从Mongoid配置中派生出mongoDB配置,所以不需要再次指定它。您的配置应如下所示:
require 'carrierwave/mongoid'
CarrierWave.configure do |config|
config.storage = :grid_fs
config.grid_fs_access_url = "/uploads" # or whatever you'd like the HTTP path to be
end