dazuma/activerecord-postgis-adapter — Issue #16: Unable to save geometries in Rails 3.2
Author: ryanwilliams
Created: 2012-02-01 02:48:04+00:00
State: open

When saving under Rails 3.2 I get this error:

NoMethodError: undefined method `rgeo_factory_settings' for Module:Class

I tracked it down to:

https://github.com/dazuma/activerecord-postgis-adapter/blob/master/lib/active_record/connection_adapters/postgis_adapter/spatial_column.rb#L136

This code assumes 'self' is the instance of the model but it's actually a weird Module created on the fly. The module_eval it runs in is here:

https://github.com/rails/rails/blob/master/activerecord/lib/active_record/attribute_methods/read.rb#L80

And the module is created by this:

https://github.com/rails/rails/blob/master/activerecord/lib/active_record/attribute_methods.rb#L56

I can't see any obvious way to make this work as is. There doesn't appear to be a way to access the model's class from inside the module.