In my Rails application I am using the Google Maps AutoComplete API to allow users to search for locations like so:

The javascript code (Gist here…) returns a JSON hash and places a new marker with the choice from the drop down box. I have a listener for the marker that does nothing right now, which leads to my question.
- How do I make the ‘click’ event for the marker pass the the result hash (in this case ‘place’) to a rails controller?
- More generally, how does one pass JavaScript data to a Rails controller at all?
I’ve looked over other answers and can’t find a solution. Any help would be greatly appreciated.
Thanks!
~Dan B,
@thoughtpunch
JQuery can serialize data in all of it’s ajax related methods; you can use this to post raw json to the server:
On your controller:
You’ll probably want to either only post the fields from your locations you care about or use
JSON.parseto unserialize your json strings for manipulation server-side.