Skip to content

Instantly share code, notes, and snippets.

@workmaster2n
Last active December 26, 2015 22:09
Show Gist options
  • Select an option

  • Save workmaster2n/7221549 to your computer and use it in GitHub Desktop.

Select an option

Save workmaster2n/7221549 to your computer and use it in GitHub Desktop.
Use postgis with nitrous.io
export DATABASE_URL=username:password@host:port/dbname
Daniel Azuma wrote the necessary gems and has a blog series on postgis/rails. Follow his instructions for the "normal" setup: http://blog.daniel-azuma.com/archives/69
#From: https://devcenter.heroku.com/articles/postgis?preview=1#setting-up-postgis-with-rails
#possible bugs: http://stackoverflow.com/questions/16547916/undefined-method-when-trying-to-build-db-with-activerecord-postgis-adapter
# in config/application.rb, before the application loads
class ActiveRecordOverrideRailtie < Rails::Railtie
initializer "active_record.initialize_database.override" do |app|
ActiveSupport.on_load(:active_record) do
if url = ENV['DATABASE_URL']
ActiveRecord::Base.connection_pool.disconnect!
parsed_url = URI.parse(url)
config = {
adapter: 'postgis',
host: parsed_url.host,
encoding: 'unicode',
database: parsed_url.path.split("/")[-1],
port: parsed_url.port,
username: parsed_url.user,
password: parsed_url.password
}
establish_connection(config)
end
end
end
end
From: https://github.com/dazuma/rgeo
gem install rgeo -- --with-geos-dir=/path/to/my/geos/installation
#note the -- to separate the build commands from the gem commands
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment