更改序列化程序中属性的格式

时间:2018-03-18 15:46:06

标签: ruby-on-rails-5 postgis

我在PostgreSQL上使用PostGIS ActiveRecord Adapter进行GIS操作和类型。在表格func panGestureEnded(_ chartView: ChartViewBase) { subscripts.fadeIn() floatingLabel.fadeOut() // clear selection by setting highlightValue to nil chartView.highlightValue(nil) } 中,我有elements类型:coordinates。在ruby中我可以做coordinates.x并返回x坐标。但是我如何在序列化器中解析它?

geometry

在开发回报中:

class ElementSerializer < ActiveModel::Serializer
  attributes :coordinates
end

在生产回报中:

"POINT (45.815927 16.00538)"

我想要类似的东西:

0101000000581CCEFC6AE8464003E962D34A013040

想要回归: class ElementSerializer < ActiveModel::Serializer attributes {:coordinates => [:coordinates.x, :coordinates.y]} end

1 个答案:

答案 0 :(得分:2)

我不知道为什么在开发环境中序列化程序会返回与生产中不同的东西,但是当涉及到您的主要问题时,您可以在ActiveModelSerializer中执行类似coordinates.x的代码 - 您只需要通过{ {1}}实例变量,所以下面的代码应该适用于你的情况:

object