1

I've got a field "location", which is an array [lng, lat].

I have two input fields in the ActiveAdmin form, defined as follows

f.inputs :name => "Location" do
  f.input :latitude
  f.input :longitude
end

In order to get latitude and longitude I have defined two getters in my model:

def latitude
  location[1]
end

def longitude
  location[0]
end

The form is shown as expected.

In order to save those value I have created two setter in the model

def latitude=(lat)
  self[:location][1] = lat.to_f
end

def longitude=(lon)
  self[:location][0] = lon.to_f
end

After the form submit those methods are called, but values are not persisted.

Do I miss something?

Mike Bevz
  • 1,266
  • 1
  • 14
  • 20

1 Answers1

0

I've found a solutions. When I used set() then it worked. save and update_attribute - didn't.

def latitude=(lat)
  self[:location][1] = lat.to_f
  self.set :location, self[:location]
end

def longitude=(lon)
  self[:location][0] = lon.to_f
  self.set :location, self[:location]
end
Mike Bevz
  • 1,266
  • 1
  • 14
  • 20