ruby on rails - NoMethodError using activerecord_postgis_adapter -
apologies if newbie question, have tried solve couple of days 0 luck.
i tried installing activerecord-postgis-adapter per readme unable create model instance keep getting error mentioned below on code pasted below that.
update
nomethoderror: undefined method `point' nil:nilclass
here different files like:
location.rb (the model, updated code)
# == schema information # # table name: locations # # id :integer not null, primary key # locatable_id :integer # locatable_type :string # created_at :datetime not null # updated_at :datetime not null # coordinates :geography({:srid point, 4326 # class location < activerecord::base #self.rgeo_factory_generator = rgeo::geos.factory_generator #set_rgeo_factory_for_column(:coordinates, # rgeo::geographic.spherical_factory(:srid => 4326) ) locfactory = rgeo::activerecord::spatialfactorystore.instance.factory(:geo_type => 'point') belongs_to :locatable, polymorphic: true validates :locatable, presence: true attr_accessor :longitude, :latitude end
gemfile
gem 'rgeo' gem 'rgeo-activerecord' gem 'activerecord-postgis-adapter'
config/application.rb
require 'rails/all' #require 'active_record/connection_adapters/postgis_adapter/railtie' #require "#{rails.root}/lib/rgeo"
config/database.yml
development: <<: *default database: geoproject-api_development adapter: postgis schema_search_path: "public,postgis"
after adding record when try retrieve it, following:
irb(main):003:0> lala = location.first location load (1.6ms) select "locations".* "locations" order "locations"."id" asc limit 1 (object doesn't support #inspect) irb(main):004:0> lala.class.name => "location" irb(main):005:0> puts lala #<location:0x007fdfd4bb2860> => nil irb(main):006:0> puts lala.inspect nomethoderror: undefined method point' nil:nilclass
wondering why or how can fix it? more specifically, why nilclass , why #inspect not being found?
from schema.rb
create_table "locations", force: :cascade |t| t.integer "locatable_id" t.string "locatable_type" t.datetime "created_at", null: false t.datetime "updated_at", null: false t.geography "coordinates", limit: {:srid=>4326, :type=>"point", :geographic=>true} end
i using rails 4.2.1.
any appreciated!
as of version 3.0.0 can't set column specific geo factory properties. , method set_rgeo_factory_for_column removed , deprecated. can, configure rgeo factory application wide. example in initializer.
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
Comments
Post a Comment