无法拆分':错误的 URI(不是 URI?):

发布于 2024-10-20 08:07:12 字数 884 浏览 0 评论 0原文

我有以下 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

阳光下慵懒的猫 2024-10-27 08:07:12

另一个解决方案是在项目根目录中添加一个“.env”文件并定义环境变量,例如:

MONGOHQ_URL=mongodb://someuser:[email protected]:10040/appid

another solution would be to add a ".env" file in the project root and define there environment variables like:

MONGOHQ_URL=mongodb://someuser:[email protected]:10040/appid
剩余の解释 2024-10-27 08:07:12

正如 KenB 所建议的,ENV['MONGOHQ_URL'] 未在我的本地计算机开发环境中设置:

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 > 

这是一个没有初始化程序的分支,因此在我的本地计算机上我必须跳过它。我是这样做的:

    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 初始化程序的更好方法,有条件地设置 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

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

窝囊感情。 2024-10-27 08:07:12

在初始化程序中,您可以执行以下操作: MongoHQ Heroku 文档

In your initializer, you can do this: URI.parse(ENV['MONGOHQ_URL'] || 'some_other_link') as specified in the MongoHQ Heroku docs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文