我如何用mongoid(3.0.17)配置载波?

时间:2013-01-24 07:04:20

标签: mongoid carrierwave

这是我的宝石列表,

  • mongo(1.8.2)
  • mongoid(3.0.17)
  • mongoid-grid_fs(1.7.0)
  • carrierwave(0.8.0)
  • carrierwave-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)
.....

有一个解决方案吗?

感谢

1 个答案:

答案 0 :(得分:0)

我快速查看the source for 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