title: Rails / PostGIS / RGeo Error: NoMethodError: undefined method `factory' for RGeo::GeoJSON::Feature
body: <p>I am using Ruby on Rails and PostGIS to store GeoJSON map data in a model called, "Map". When I save an object loaded successfully with a simple GeoJSON feature I get the error, "NoMethodError: undefined method `factory' for #".</p>
  
  <p>See below for examples, setup, what I've tried, and links to resources.</p>
  
  <h1>Example 1 (using Rails console)</h1>
  
  <pre><code>irb(main):007:0&gt; feature = '{ "type": "Feature", "properties": {  "name": "Coors Field",  "amenity": "Baseball Stadium",  "popupContent": "This is where the Rockies play!" }, "geometry": {  "type": "Point",  "coordinates": [-104.99404, 39.75621] }}'
  =&gt; "{ \"type\": \"Feature\", \"properties\": {  \"name\": \"Coors Field\",  \"amenity\": \"Baseball Stadium\",  \"popupContent\": \"This is where the Rockies play!\" }, \"geometry\": {  \"type\": \"Point\",  \"coordinates\": [-104.99404, 39.75621] }}"
  
  irb(main):008:0&gt; geom_feature = RGeo::GeoJSON.decode(feature)
  =&gt; #&lt;RGeo::GeoJSON::Feature:0x304e48c id=nil geom="POINT (-104.99404 39.75621)"&gt;
  
  irb(main):009:0&gt; Map.create(name: 'demo', geometry: geom_feature)
     (0.9ms)  BEGIN
     (0.6ms)  ROLLBACK
  NoMethodError: undefined method `factory' for #&lt;RGeo::GeoJSON::Feature:0x000000000609c918&gt;
    from (irb):9
  </code></pre>
  
  <h1>Setup</h1>
  
  <ul>
  <li>Rails 5.1.4</li>
  <li>PostGIS 9.6</li>
  <li>Docker DB src: kartoza/postgis:9.6-2.4</li>
  <li>Docker web src: ruby 2.3.5</li>
  </ul>
  
  <h1>Files</h1>
  
  <p>config/initializers/rgeo.rb</p>
  
  <pre><code>RGeo::ActiveRecord::SpatialFactoryStore.instance.tap do |config| 
    config.default = RGeo::Geographic.spherical_factory(srid: 4326) 
  end
  </code></pre>
  
  <p>Gemfile</p>
  
  <pre><code># Mapping
  gem 'activerecord-postgis-adapter'
  gem 'rgeo'
  gem 'rgeo-geojson'
  # need this? found on random post - willing to try anything
  gem 'rgeo-activerecord'
  </code></pre>
  
  <p>db/migrate/20182039293939_create_maps.rb</p>
  
  <pre><code>create_table :maps do |t|
    t.string :name
    t.st_polygon :polygon
    t.geometry :geometry
    t.multi_polygon :multi_polygon
    t.references :mappable, polymorphic: true, index: true
  
    t.timestamps
  end
  </code></pre>
  
  <h1>Sources</h1>
  
  <p>Among others I've gone through the following sources without any luck:</p>
  
  <p><a href="http://daniel-azuma.com/articles/georails/part-2" rel="nofollow noreferrer">Daniel Azuma's original post about setup from 2011</a></p>
  
  <p><a href="https://stackoverflow.com/questions/30834862/nomethoderror-using-activerecord-postgis-adapter">StackOverflow post that talks about why part of that is obsolete 2015-06-26</a></p>
  
  <ul>
  <li>Note the comment below the accepted answer that clarifies how to set a default spherical factory for everything - which is fine for me and what I did above.</li>
  </ul>
  
  <p><a href="https://github.com/rgeo/rgeo-geojson/issues/34" rel="nofollow noreferrer">Github issue response that doesn't seem relevant given that this is already a single feature</a></p>
  
  <p><a href="https://github.com/rgeo/activerecord-postgis-adapter/issues/185" rel="nofollow noreferrer">More recent and active Github activerecord-postgis-adaptor response that hit on all points above</a></p>
  
  <p><a href="https://github.com/rgeo/activerecord-postgis-adapter/issues/190" rel="nofollow noreferrer">Suggests that despite not using Geos the install needs to be wrestled with 2015</a></p>
  
  <ul>
  <li>I'm still messing with this option despite it not seeming relevant</li>
  <li>Tried and had no effect (see below)</li>
  </ul>
  
  <h1>Attempts</h1>
  
  <p>I also tried installing Geos but this made no difference.</p>
  
  <p>In container:</p>
  
  <pre><code>apt install libgeos-dev
  gem uninstall rgeo &amp;&amp; gem install rgeo
  </code></pre>
  
  <p>In Rails Console: (after restart)</p>
  
  <pre><code>irb(main):001:0&gt; RGeo::Geos.supported?
  =&gt; true
  </code></pre>
  
  <p>Attempt and outcome same as above (Example 1)</p>