问题描述
我有以下CarrierWave初始化程序,可在我的Heroku / MONGOHQ / GridFS env上正常工作:
I've got the following CarrierWave initializer which works fine on my Heroku/MONGOHQ/GridFS env :
CarrierWave.configure do |config|
config.storage = :grid_fs
uri = URI.parse(ENV['MONGOHQ_URL'])
config.grid_fs_database = File.basename(uri.path)
config.grid_fs_host = uri.host unless uri.host.blank?
config.grid_fs_port = uri.port unless uri.port.blank?
config.grid_fs_username = uri.user unless uri.user.blank?
config.grid_fs_password = uri.password unless uri.password.blank?
config.grid_fs_access_url = '/gridfs'
config.cache_dir = "uploads"
config.root = Rails.root.join('tmp')
end
但是,当我尝试在开发中本地运行代码时,出现以下错误:
but, when I try to run the code locally (in developement) I get the following error:
`split': bad URI(is not URI?): (URI::InvalidURIError)
这里是完整的堆栈:我试图在初始化程序的顶部添加require'uri / generic'但不起作用。
here is the full stack : http://pastie.org/1630069 I tried to add require 'uri/generic' on top of initializer but doesn't works.
有人知道吗?
预先感谢
luca
Does anybody know way ?Thanks in advanceluca
推荐答案
如KenB所建议,ENV ['MONGOHQ_URL']不是在我的本地机器开发环境上设置:
As suggested by KenB the ENV['MONGOHQ_URL'] was not setted on my local machine developement environment :
lsoave@ubuntu:~/rails/heroku/mp3upload$ rails c
Loading development environment (Rails 3.0.5)
ruby-1.9.2-p136 :001 > ENV['MONGOHQ_URL']
=> nil
ruby-1.9.2-p136 :002 >
这是一个没有初始化程序的分支,因此在我的本地计算机上,我不得不跳过它。我是这样做的:
this was a branch without the initializer, so on my local machine I had to skip that. I did it like that:
if ENV['MONGOHQ_URL']
CarrierWave.configure do |config|
config.storage = :grid_fs
uri = URI.parse(ENV['MONGOHQ_URL'])
config.grid_fs_database = File.basename(uri.path)
config.grid_fs_host = uri.host unless uri.host.blank?
config.grid_fs_port = uri.port unless uri.port.blank?
config.grid_fs_username = uri.user unless uri.user.blank?
config.grid_fs_password = uri.password unless uri.password.blank?
config.grid_fs_access_url = '/gridfs'
config.cache_dir = "uploads"
config.root = Rails.root.join('tmp')
end
end
我认为这是在引导过程中跳过Ralis 3.0.5初始化程序的更好方法
I think that should be a very better way to skip a Ralis 3.0.5 initializer during the boot process, conditionally to the ENV['MONGOHQ_URL'] parameter value.
如果有更好的方法,可以请您分享一下吗?
非常感谢:-)
luca
If you have a better way, could you please share it ?Many thanks :-)luca
这篇关于无法分割':错误的URI(不是URI?):的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!