Sending data via Ajax and processing it on the action controller

I am trying to send some geolocation data via Ajax and process it with a specific controller action.

The code (which is in the view) looks like this:

$.ajax({ type: "GET", url: "/save_location", data: "lat=" + position.coords.latitude + "&long=" + position.coords.longitude }); 

I have a save_location action which is in the users controller :

  def save_temp_location cookies[:lat] = params[:lat] cookies[:long] = params[:long] end 

I want to temporarily save this data while the user browses the site. In my view, I tried to display the values โ€‹โ€‹of cookies[:lat] and cookies[:long] to check if it works or not: Unfortunately, nothing is displayed. I looked at the console when a GET request was made (the route is correct):

 Started GET "/save_location?lat=48.856666&long=2.350987" for 127.0.0.1 at 2011-05-09 12:02:25 +0100 Processing by UsersController#save_temp_location as Parameters: {"lat"=>"48.856666", "long"=>"2.350987"} Redirected to http://fr.localhost.dev:3000/ Completed 302 Found in 1ms 

I tried to debug by placing in this action: puts "foo" or raise "foo" , but nothing happens (however, I get the corresponding behavior when viewing manually in / save _location). Is there a 302 http code , is there anything related to this? (and what does this mean in this context?).

What do you think is wrong? Did I miss a very important point?

Thanks!

+4
source share
1 answer

Are you being redirected by a filter?

+1
source

All Articles