【发布时间】:2012-08-11 20:30:59
【问题描述】:
我有一个字段“位置”,它是一个数组 [lng, lat]。
我在ActiveAdmin表单中有两个输入字段,定义如下
f.inputs :name => "Location" do
f.input :latitude
f.input :longitude
end
为了获得纬度和经度,我在我的模型中定义了两个吸气剂:
def latitude
location[1]
end
def longitude
location[0]
end
表单按预期显示。
为了保存这些值,我在模型中创建了两个 setter
def latitude=(lat)
self[:location][1] = lat.to_f
end
def longitude=(lon)
self[:location][0] = lon.to_f
end
在表单提交之后,这些方法被调用,但值不会被持久化。
我错过了什么吗?
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-3 mongoid activeadmin mongoid3