开发者

Using JSON input in Ruby method on Rails

开发者 https://www.devze.com 2022-12-24 04:56 出处:网络
I am using jQuery to make an AJAX call to a ruby method in my controller. The javascript looks something like this:

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'开发者_Python百科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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消