updating an array from form fields

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

After investigating the problem more I found a solution so I'd like to post it here for anyone that has a similar problem.

Form field inputs are available to the controller through the 'params' variable. I accessed this variable in the controller on the form submit action and called a method I created in the model to persist the database field. The method in the model takes the lat and lng as arguments and sets the location field with the values of those variables.

Best, Andreas