sferik/rails_admin — pull request #881 by erictheise (2011-12-15 00:43:46+00:00)
Title: Add spatial type

We've geo-enabled a Rails 3.1 app using the RGeo gem with a PostgreSQL database and PostGIS extensions. rails_admin can't handle tables with the spatial type.

I'm contributing two very simple files:

1. A minimal lib/rails_admin/config/fields/types/spatial.rb based on the other minimal types such as float.rb

2. lib/tasks/spatial_type.rake

rake rails_admin:spatial_disable # Remove spatial field type
rake rails_admin:spatial_enable # Add spatial field type for use with PostGIS

The disable task removes any line in lib/rails_admin/config/fields/types/all.rb that requires spatial.rb. The enable task is more cautious, verifying that the database connector is 'PostGIS', then adding a line to lib/rails_admin/config/fields/types/all.rb requiring spatial.rb.

Once enabled, rails_admin will display the Well-Known Text (WKT) form of a spatial object, e.g.,

POINT (-121.260685 37.917075)

See http://postgis.refractions.net/documentation/manual-1.5/ch04.html#OpenGISWKBWKT

The goal is to have no impact on the 99.99% of rails_admin users who have no use for PostGIS, but to make it easier for the tiny (but growing?) percent that do.

It's likely I'll make additions to spatial.rb as our app develops.

Thanks for your consideration, Eric