开发者

What happened to Mongoid.config.master.connection.host?

I am trying to get Carrierwave (0.5.1) to work with Mongoid (2.0.0.beta.20), Rails 3. I followed every step at this guide.

In config/initializers/carrierwave.rb, I have:

CarrierWave.configure do |config|
  config.grid_fs_database = Mongoid.database.name
  config.grid_fs_host = Mongoid.config.master.connection.host
  config.storage = :grid_fs
  config.grid_fs_access_url = "/uploads"
end

When I try to start my server (rails server). In the console, I get:

...config/initializers/carrierwave.rb:3:in `block in <top
(required)>': undefined method `host' for #<Mongo::Connection:
0x00000103802420> (NoMethod开发者_C百科Error)

I don't understand why I am getting this error. I've looked everywhere and can't seem to locate why this is happening...

It seems, Mongoid.config.master.connection.host doesn't work anymore in newer versions of Mongoid. Was this removed? What is the replacement for this?

So far my workaround is the following code:

CarrierWave.configure do |config|
  config.grid_fs_database = Mongoid.database.name
  config.grid_fs_host = 'localhost'
  config.storage = :grid_fs
  config.grid_fs_access_url = "/uploads"
end

Line 3, should be: config.grid_fs_host = 'localhost'. <-- Is there a better way to dynamically indicate the host depending on environment?


Found out that the mongo gem has changed. So it now has to be:

config.grid_fs_host = Mongoid.database.connection.primary_pool.host
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜