1

I am assembling data into an array for an ajax call to a Rails controller action. Unfortunately, I don't know how to append the values of this array onto my query string so that they will end up in the params object inside my controller action.

The array is a simple array of strings.

my_ids = ["1","2","3"]

My main query string is a serialized form.

I want to add this so that in my controller action:

params[:my_ids] == ["1","2","3"]

What can I do?

I am using Rails 3.2 and jQuery.

RubyRedGrapefruit
  • 12,066
  • 16
  • 92
  • 193

1 Answers1

1

Try:

$.ajax({
        url: '/controller/action',
        type: 'POST',
        dataType: "json",
        data: { 
            my_ids: JSON.stringify(my_ids)
        },
        success: function () { alert('success'); },
        error: function (event, request, settings) {  
            alert('Error' + ' : ' + settings); }
});
mccannf
  • 16,619
  • 3
  • 51
  • 63