I am hoping someone can please help me with this. I am trying to pass
an array using Ajax.Request and cannot get it working. This is what I
have so far:
It seems like there is a better way to pass an array with Ajax.request
into a controller and have it interpreted into a ruby array. Using
link_to_remote, you are able to pass an array using :with ->
So Ive decided it might be better to take a step backwards and explain
what I am trying to do to because there may be a better way of doing
it. I have an array of hashes and each hash correlates to an active
record object. Now what I need to do is pass this array to a
controller action using Ajax.Request somehow. I could really use some
help, Ive tried many different ways but none have worked! Thanks.
That depends on what you need the AR objects for, if they are records
that already exist in your database and your controller only need the
reference to them, you'ld be better off passing just the ids (and type
if they differ) and having your controller action fetch the records.
If the data in the active records has changed, or isn't yet in the
database, I'd have to recommend either using serializing them into a
form to submit to the controller action or turning them into json as
mentioned above.
The response from your test of #to_json you showed before
"data"=>"[object Object]" doesn't seem right, as the result should be
a string representation of all object's in the array (and all object
attributes & values)
experiment with it in the console, to get it working, try data.to_json
should work just fine, showing something like: