views:

28

answers:

0

So I have this weird problem with jquery doing a ajax post with a ruby object. I have 2 options. 1. $('form_id'}.serialize(). I know this works. But my form simply has too many fields, and it is a little too inconvenient to manage them in the form 2. Second option, the rails controller is constructing a ruby object along the way as the form is being edited. This is super convenient only if I can simply stick in the object in the ajax post request. Apparently I am able to, with something like this...

some_function() {
  $.ajax( {type: post, url: '/action', data: { 'post_data': <%= @ruby_object.to_json %> }});
}

If you wonder this works, it does. (dunno how and why) But there is a small problem. the ruby object has a array of hashes within a hash, like this { [ {} ] } It appears that someone somewhere is converting that array to a hash with keys which are indices of that array. So in the action, if i print the parameters, I get { { {} } }. So can someone tell me how not to get this and get back exactly the original object structure?