在Heroku上启用Ruby PostGIS支持 [英] Enabling Ruby PostGIS support on Heroku

查看:83
本文介绍了在Heroku上启用Ruby PostGIS支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Heroku上的Rails应用中启用PostGIS.我的Gemfile包括activerecord-postgis-adapter宝石:

I'm trying to enable PostGIS in my Rails app on Heroku. My Gemfile includes the activerecord-postgis-adapter gem:

gem 'activerecord-postgis-adapter', '3.0.0'

但是,在启动实例后,我看不到启用了完全支持:

However, after booting up my instance, I don't see full support enabled:

$ heroku run irb
Running `irb` attached to terminal... up, run.5549
irb(main):001:0> require 'rgeo'
=> true
irb(main):002:0> RGeo::Geos.supported?
=> false

我已经添加了 heroku-geo-buildpack PostGIS文章,尽管我使用的是更新的,真正的多构建包格式:

I've added the heroku-geo-buildpack,as specified in the PostGIS article, though I'm using the newer, true multi-buildpack format:

$ heroku buildpacks
=== staging Buildpack URLs
1. https://github.com/cyberdelia/heroku-geo-buildpack.git#1.3
2. https://github.com/heroku/heroku-buildpack-ruby.git#v140

我很困惑,因为我的构建过程看起来是正确的:

I'm confused, since my build process looks correct:

-----> Multipack app detected
-----> Fetching custom git buildpack... done
-----> geos/gdal/proj app detected
       Using geos version: 3.4.2
       Using gdal version: 1.11.1
       Using proj version: 4.8.0_1
-----> Vendoring geo libraries done
-----> Fetching custom git buildpack... done
-----> Ruby app detected
-----> Compiling Ruby/Rails
...

我想念什么?我没有设置BUILDPACK_URL环境变量,因为我收集到的是旧的多生成包方法.

What am I missing? I don't have a BUILDPACK_URL environmental variable set, as I gather it's for the old multi-buildpack approach.

推荐答案

PostGIS可以与Heroku Free dyno和:
一起使用. -Rails 4.2
-activerecord-postgis-adapter 3.1.4

PostGIS does work with Heroku Free dyno and :
- Rails 4.2
- activerecord-postgis-adapter 3.1.4

您必须:

  1. 像这样设置您的config/database.yml:


default: &default
  adapter: postgis
  encoding: unicode
  # For details on connection pooling, see rails configuration guide
  # http://guides.rubyonrails.org/configuring.html#database-pooling
  pool: 5

development:
  <<: *default
  database: adopt_your_geek_development
  username: postgres
  host: mydb.com
  port: 9999
  postgis_extension: postgis
  schema_search_path: public,postgis

...

production:
  <<: *default
  database: appname_production
  username: appname
  password: <%= ENV['ADOPT_YOUR_GEEK_DATABASE_PASSWORD'] %>
  postgis_extension: postgis
  schema_search_path: public,postgis


  1. 添加构建包:


$ heroku buildpacks:add https://github.com/ddollar/heroku-buildpack-multi.git

使用以下.buildpacks文件:

With the following .buildpacks file:

$ cat .buildpacks 
https://github.com/cyberdelia/heroku-geo-buildpack.git
https://github.com/heroku/heroku-buildpack-ruby.git


  1. 然后在config/environments/production.rb中添加一个小猴子补丁


module ActiveRecord
   module ConnectionHandling
     class MergeAndResolveDefaultUrlConfig
       private
       def config
         @raw_config.dup.tap do |cfg|
           if url = ENV['DATABASE_URL']
             cfg[@env] ||= {}
             cfg[@env]["url"] ||= url.try(:gsub, "postgres", "postgis")
           end
         end
       end
     end
   end
end


我现在使用免费的postgres在Heroku免费dyno上为我工作.


I works for me right now on Heroku free dyno with free postgres.

这篇关于在Heroku上启用Ruby PostGIS支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆