0

这是我的宝石清单,

  • 蒙戈(1.8.2)
  • mongoid (3.0.17)
  • mongoid-grid_fs (1.7.0)
  • 载波 (0.8.0)
  • 载波-mongoid (0.4.0)

我试图生成上传图像,但它不起作用,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)
.....

有解决方案吗?

谢谢

4

1 回答 1

0

我快速查看了carrierwave-mongoid 的来源,您指定的配置选项(grid_fs_databasegrid_fs_portgrid_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
于 2013-01-24T13:22:27.773 回答