I''m using the GeoRuby and Spatial Adapter to do some postgis stuff with
rails. Working great. The thing is, these define custom types that get
stored on these activerecord objects. Things like
GeoRuby::SimpleFeatures::Point. So when I call to_xml everything is
peachy except for that datatype.
<biological-metric>
<biomass type="float">0.0</biomass>
<climate>Temperate</climate>
<country>Canada</country>
<density type="float">11.0</density>
<diversity type="float">0.0</diversity>
<geometry type="geometry">
#<GeoRuby::SimpleFeatures::Point:0x34b4238>
</geometry>
<id type="integer">2</id>
<organism-size type="float">-1.0</organism-size>
<reserve-name>Ecological reserve</reserve-name>
</biological-metric>
So what I did was define to_json and to_xml methods for these types.
They work fine.
>> BiologicalMetric.find(:first).geometry.to_xml
=>
<?xml version="1.0" encoding="UTF-8"?>
<point>
<latitude>-123.333297729</latitude>
<longitude>49.0</longitude>
</point>
So I thought that this would solve all my problems and even be something
I could contribute to the georuby library. Very DRY eh? Wrong!!!
ActiveRecord doesn''t seem to call the to_xml method on these datatypes.
It just does it''s own thing. The JSON serialization ignores the custom
methods as well.
Am I missing something? Why wouldn''t to_xml/to_json be called when the
parent object''s to_xml/to_json method is called?
Thanks,
Chad Burt
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---