title: Passing AJAX variables to rails controller
body: <p>I'm using gmaps4rails in a javascript callback function to determine the user's location and then plot this location on a map. I then want to access this location info in the controller and use ruby geocoder to query for nearby events. According to firebug console I can see that the latitude, longitude co-ordinates are being posted but when i try to access these params in the controller it's not working - that is i'm not getting any errors but no events are being displayed on the map ( however if i type the user address directly into the controller code the nearby events are being displayed). See my code below. Any help/suggestions would be greatly appreciated.</p>
  
  <p><strong>Callback in events/index.html.erb</strong></p>
  
  <pre><code> &lt;% content_for :scripts do %&gt;
      &lt;script type="text/javascript"&gt;
      var lat;
      var lng;
  
  Gmaps.map.geolocationSuccess = function(){
        if(Gmaps.map.callback){
          lng = Gmaps.map.userLocation.lng();
          lat = Gmaps.map.userLocation.lat();
          Gmaps.map.addMarkers([{
              "lng": lng,
              "lat": lat,
              "picture": "http://gmaps-samples.googlecode.com/svn/trunk/markers/pink/blank.png",
              "width": "37",
              "height": "34"
          }]);
  
      $.ajax({
              type: 'POST',
              url: 'events/index',
              dataType: 'json',
              data: "latitude=" + lat + "&amp;longitude=" + lng,          
            });
        }
      };     
  
      &lt;/script&gt;
      &lt;% end %&gt;
  </code></pre>
  
  <p><strong>Events Controller</strong></p>
  
  <pre><code>  def index
      @events = Event.near(params[:latitude], params[:longitude],2)
      @json = @events.to_gmaps4rails
  
      respond_to do |format|
        format.html # index.html.erb
        format.js {render json: @events, content_type: 'text/json' }
     end
   end
  </code></pre>