Hi,
A form in our view is currently updating two fields :lat and :lng in a
model named Event, but we would like to update a :location array
variable using the form instead. E.g the location variable could
contain [{:lat => 45.1, :lng => -3.4}] (order of lat and lng matters).
If you have any suggestions on how to do this, please let me know.
The event model looks like this:
class Event
include Mongoid::Document
…
// location array should have the value lat first and lng second.
// e.g location = [{:lat => 45.1, :lng => -3.4}]
field :location, :type => Array, :geo => true
field :lat, :type => BigDecimal
field :lng, :type => BigDecimal
…
end
The events edit view that updates the model looks like:
:javascript
$(document).ready(function(){
var options = {
map_frame_id: “mapframe”,
map_window_id: “mapwindow”,
lat_id: “event_lat”,
lng_id: “event_lng”,
addr_id: “event_address”,
map_zoom: 13
}
$(’#event_address’).autogeocomplete(options);
});
= form_for @event do |f|
…
#mapframe
#mapwindow
//We need to update the location field in class Event with the
values provided by the javascript
//instead of the fields ‘lat’ and ‘lng’ (that is what we are doing now)
= f.hidden_field :lat
= f.hidden_field :lng
.actions
= f.submit ‘Save’
Best,
Andreas