How to set up a postgis-adaptered Ruby on Rails app for Heroku deployment? -
i have following:
gems:
gem 'pg', '~> 0.18' gem 'activerecord-postgis-adapter', '4.0.0' gem 'rgeo-geojson'
initializer: config/initializers/rgeo.rb
require 'rgeo-activerecord' rgeo::activerecord::spatialfactorystore.instance.tap |config| # default, use geos implementation spatial columns. config.default = rgeo::geos.factory_generator # use geographic implementation point columns. config.register(rgeo::geographic.spherical_factory(srid: 4326), geo_type: "point") end
database settings: config/database.yml
default: &default adapter: postgis encoding: unicode username: appname_u password: password su_username: appname_su su_password: pa55w0rd schema_search_path: "public, postgis" pool: <%= env.fetch("rails_max_threads") { 5 } %> development: <<: *default database: appname_development script_dir: /usr/local/opt/postgis/share/postgis test: <<: *default database: appname_test script_dir: /usr/local/opt/postgis/share/postgis production: <<: *default database: appname_production url: <%= env.fetch('database_url', '').sub(/^postgres/, "postgis") %> username: unfold password: <%= env['unfold_database_password'] %>
enable postgis extension of heroku postgresql:
$ heroku pg:psql --app ngrails-unfold > create extension postgis; > select postgis_version(); postgis_version --------------------------------------- 2.3 use_geos=1 use_proj=1 use_stats=1 (1 row)
data model migration:
class createlocations < activerecord::migration[5.0] def change create_table :locations |t| t.string :name, null: false t.st_point :latlon, geographic: true, null: false t.timestamps end add_index :locations, :name end end
build packs:
1. possibly frontend app buildpack 2. https://github.com/cyberdelia/heroku-geo-buildpack.git or https://github.com/desaperados/heroku-buildpack-geo.git 3. heroku/ruby
but still error in production:
nomethoderror (undefined method `property' nil:nilclass) ——— logs ———
heroku[router]: at=info method=post path="/api/locations.json" host=yourappname.herokuapp.com request_id=4053b701-9d3e-479c-8a33-c44e539ccdc8 fwd="45.63.35.55" dyno=web.1 connect=3ms service=28ms status=500 bytes=551 started post "/api/locations.json" 45.63.35.55 @ 2016-11-15 14:36:41 +0000 processing locationscontroller#create json parameters: {"location"=>{"name"=>"san francisco airport", "latlon"=>"point(-122.381827 37.62161)"}} begin location exists (1.7ms) select 1 one "locations" "locations"."name" = $1 limit $2 [["name", "san francisco airport"], ["limit", 1]]
——— error logs heroku ———
rollback completed 500 internal server error in 15ms (activerecord: 6.1ms) nomethoderror (undefined method `property' nil:nilclass): app/controllers/locations_controller.rb:20:in `create'
——— success logs localhost ———-
insert "locations" ("name", "latlon", "created_at", "updated_at") values ($1, $2, $3, $4) returning "id" [["name", "san francisco airport"], ["latlon", "0020000001000010e6c05e986fda836eb54042cf90ea9e6eeb"], ["created_at", 2016-11-15 14:35:29 utc], ["updated_at", 2016-11-15 14:35:29 utc]] commit
so correct steps set postgis-adaptered rails app on heroku?
btw, app runs smoothly on localhost. unable sort out on heroku.
they have explanation on heroku website:
https://devcenter.heroku.com/articles/sqlite3
you should check out , follow step step
Comments
Post a Comment