无法拆分':错误的 URI(不是 URI?):
我有以下 CarrierWave 初始化程序,它在我的 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
但是,当我尝试在本地运行代码(在开发中)时,我收到以下错误:
`split': bad URI(is not URI?): (URI::InvalidURIError)
这是完整的堆栈:http://pastie.org/1630069 我尝试在初始化程序之上添加 require 'uri/generic' 但不起作用。
有谁知道方法吗? 提前致谢 卢卡
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)
here is the full stack : http://pastie.org/1630069 I tried to add require 'uri/generic' on top of initializer but doesn't works.
Does anybody know way ?
Thanks in advance
luca
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另一个解决方案是在项目根目录中添加一个“.env”文件并定义环境变量,例如:
another solution would be to add a ".env" file in the project root and define there environment variables like:
正如 KenB 所建议的,ENV['MONGOHQ_URL'] 未在我的本地计算机开发环境中设置:
这是一个没有初始化程序的分支,因此在我的本地计算机上我必须跳过它。我是这样做的:
我认为这应该是在引导过程中跳过 Ralis 3.0.5 初始化程序的更好方法,有条件地设置 ENV['MONGOHQ_URL'] 参数值。
如果您有更好的方法可以分享一下吗?
非常感谢:-)
卢卡
As suggested by KenB the ENV['MONGOHQ_URL'] was not setted on my local machine developement environment :
this was a branch without the initializer, so on my local machine I had to skip that. I did it like that:
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.
If you have a better way, could you please share it ?
Many thanks :-)
luca
在初始化程序中,您可以执行以下操作: MongoHQ Heroku 文档
In your initializer, you can do this:
URI.parse(ENV['MONGOHQ_URL'] || 'some_other_link')
as specified in the MongoHQ Heroku docs