1

I am using jQuery to make an AJAX call to a ruby method in my controller. The javascript looks something like this:

var latLongJSON = {
  "address": [{
    "lat": 50,
    "long": 50
  }]
};

var returnedAddresses;

$.ajax({
  type: "GET",
  data: latLongJSON,
  url: "map/getaddresses",
  success: function(data) {
    returnedAddresses = JSON.parse(data);
  }
});

Then in my 'getaddresses' method, my parameter coming through looks like:

Parameters: {"address"=>"[object Object]"}

I'm not sure what to do with this. I'm fairly new to Ruby, and I'm not sure if I need to convert this to something else, or what. Ideally I want to be able to pass in multiple sets of lat/long in the 'address' array, then be able to iterate over those in my Ruby code.

2
  • What version of jQuery are you using? Commented Mar 28, 2010 at 16:57
  • I think 1.3.2 - it's what came with jRails. Commented Mar 28, 2010 at 17:00

1 Answer 1

1

Try out jQuery 1.4.2, it as much better handling of passing objects back to the server.

The param function was rewritten in 1.4.* to handle padding back deep arrays and object.

Sign up to request clarification or add additional context in comments.

2 Comments

Looks like that helped quite a bit, but I'm still not sure how to handle the parameters: Parameters: {"address"=>{"0"=>{"lat"=>"50", "long"=>"50"}}} Do I need to convert that into a Hash, or how else would I iterate over it?
Nevermind - that was my Ruby newbieness shining through. That is in a hashmap. Thanks for the suggestion.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.