Ruby on rails 如何为Heroku部署设置postgis适配Ruby on Rails应用程序? 我有以下资料:
宝石: 初始化器:config/initializers/rgeo.rbRuby on rails 如何为Heroku部署设置postgis适配Ruby on Rails应用程序? 我有以下资料:,ruby-on-rails,heroku,postgis,rgeo,Ruby On Rails,Heroku,Postgis,Rgeo,宝石: 初始化器:config/initializers/rgeo.rb require 'rgeo-activerecord' RGeo::ActiveRecord::SpatialFactoryStore.instance.tap do |config| # By default, use the GEOS implementation for spatial columns. config.default = RGeo::Geos.factory_generator # B
require 'rgeo-activerecord'
RGeo::ActiveRecord::SpatialFactoryStore.instance.tap do |config|
# By default, use the GEOS implementation for spatial columns.
config.default = RGeo::Geos.factory_generator
# But use a geographic implementation for point columns.
config.register(RGeo::Geographic.spherical_factory(srid: 4326), geo_type: "point")
end
数据库设置: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'] %>
数据模型迁移:
class CreateLocations < ActiveRecord::Migration[5.0]
def change
create_table :locations do |t|
t.string :name, null: false
t.st_point :latlon, geographic: true, null: false
t.timestamps
end
add_index :locations, :name
end
end
但我仍然在生产中遇到错误:
NoMethodError(nil:NilClass的未定义方法'property')
---日志---
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" for 45.63.35.55 at 2016-11-15 14:36:41 +0000
Processing by LocationsController#create as JSON
Parameters: {"location"=>{"name"=>"San Francisco Airport", "latlon"=>"POINT(-122.381827 37.62161)"}}
BEGIN
Location Exists (1.7ms) SELECT 1 AS one FROM "locations" WHERE "locations"."name" = $1 LIMIT $2 [["name", "San Francisco Airport"], ["LIMIT", 1]]
ROLLBACK
Completed 500 Internal Server Error in 15ms (ActiveRecord: 6.1ms)
NoMethodError (undefined method `property' for nil:NilClass):
app/controllers/locations_controller.rb:20:in `create'
---来自heroku的错误日志---
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" for 45.63.35.55 at 2016-11-15 14:36:41 +0000
Processing by LocationsController#create as JSON
Parameters: {"location"=>{"name"=>"San Francisco Airport", "latlon"=>"POINT(-122.381827 37.62161)"}}
BEGIN
Location Exists (1.7ms) SELECT 1 AS one FROM "locations" WHERE "locations"."name" = $1 LIMIT $2 [["name", "San Francisco Airport"], ["LIMIT", 1]]
ROLLBACK
Completed 500 Internal Server Error in 15ms (ActiveRecord: 6.1ms)
NoMethodError (undefined method `property' for nil:NilClass):
app/controllers/locations_controller.rb:20:in `create'
---来自localhost的成功日志----
INSERT INTO "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
那么,在Heroku上设置postgis适配Rails应用程序的正确步骤是什么
顺便说一句,该应用程序在本地主机上运行平稳。无法在Heroku上进行分类。他们在Heroku网站上有很好的解释:
你应该检查一下,然后一步一步地进行操作。Heroku网站上有一个非常好的解释:
你应该检查一下,然后一步一步地进行操作这与POSTGIS有什么关系?这与POSTGIS有什么关系?你是如何解决的?你是如何解决的?
INSERT INTO "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