Y
Y
yezolux2014-12-02 02:05:47
Ruby on Rails
yezolux, 2014-12-02 02:05:47

How to pass variables from js to Ruby on Rails controller?

I'm trying to solve the problem of determining the user's geolocation to display the correct content.
I made the definition of the city by ip, but the accuracy suffers. There are 50 to 50 hits from computers, and 0 from mobile devices with 3G. As an option, I decided to add a city definition by coordinates (navigator.geolocation).
I did something like this in js

$(document).ready(function() {
  if(navigator.geolocation)
    navigator.geolocation.getCurrentPosition(function(position) {
      var latitude = position.coords.latitude;
      var longitude = position.coords.longitude;
    });
});

How can I pass latitude and longitude to the controller for further work. I want to substitute coordinates in geocoder to get the city.
Geocoder.search(latitude,longitude)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Wolf, 2014-12-02
@yezolux

ajax + sessions?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question