title: how do i pass location coordinate getting from HTML5 & javascript to my rails controller and mongodb model ?
body: <p>I am working on a web app where I want to get user's current geolocation coordinates (Latitude. Longitude, Altitude). I am using Ruby on Rails with MongoDB (mongoid). 
  I am getting users coordinate through HTML5 and Javascript. </p>
  
  <p>for now I am displaying those coordinate in users/new.html.erb where I lodad a script in the head of new.html.erb such as </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;script&gt;
  function getUserLocation() { 
  
  //check if the geolocation object is supported, if so get position
  if (navigator.geolocation)
      navigator.geolocation.getCurrentPosition(displayLocation, displayError);
  else
      document.getElementById("locationData").innerHTML = "Sorry - your browser doesn't support geolocation!";
  }
  
  function displayLocation(position) { 
  
  //build text string including co-ordinate data passed in parameter
  var displayText = "User latitude is " + position.coords.latitude + " longitude is " + position.coords.longitude + " and altitude is " + position.coords.altitude;
  
  var loc = [[position.coords.latitude, position.coords.longitude][position.coords.altitude]]
  
  //display the string for demonstration
  document.getElementById("locationData").innerHTML = displayText;
  }
  &lt;/script&gt;
  
  &lt;/head&gt;
  </code></pre>
  
  <p>and in body tag I am requesting user to click on a button to get the cordinate display. </p>
  
  <pre><code>&lt;input type="button" value="get location" onclick="getUserLocation()"/&gt;
  &lt;div id="locationData"&gt;
  Location Data
  &lt;/div&gt;
  </code></pre>
  
  <p>what I want to do is, transfer this location data (var loc) to my model places. The mongoid model is like below</p>
  
  <pre><code>model/place.rb
  
  class Place
    include Mongoid::Document
     belongs_to :user
    embeds_one :location
    index({location: "2dsphere"})
  end
  
  model/location.rb
  
  class Location
    include Mongoid::Document
     field :type, type: String
    field :coordinates, type: Array
    embedded_in :place
  
  end
  </code></pre>
  
  <p>I want to know how can I pass javascript variable as a parameters to controller#new method and then to my model place where location is an embedded document.</p>
  
  <p>Can someone please help with this? </p>