views:

323

answers:

3

I am trying to submit a create and update request to rails using flex with multiple models. For example, imagine that we have a blog post and multiple comments.

The user comes and update the post and some comments, when he clicks on submit I want to send all updates.

If I send something like:

var params:Object = new Object();

params["post[text]"] = myPostText;

params["post[userid]"] = myPostUserId;

Then I can send a array with the comments: var ar:Array = ["comment 1", "comment 2"]; params["post[comments]"] = ar;

This work without problems (avoiding the problem with multiple attributes having the same name).

But my problem is that for the comments I need to submit multiple attributes, lets suppose that for each comment I need to submit a rank, I tried to do (pseudo code):

var ar:Array = new Array();

for each comment c {

ar.push({"text":c.text, "rank":c.rank});

}

params["post[comments]"] = ar;

This does not work, because for each comment the hash parameters on rails side will contain the string "[object Object]".

Does anyone know a way to submit multiple models on flex to rails?

A: 

Any one has solution for this?

Shuai Zhang
A: 

Actually I have it. Forget using those parameters objects and use only XML, its easier than those parameters objects and you can have a single way to serialize your flex objects.

Using XML you just need to build it with the objects nested (like rails does for you).

The only issue is that you cannot use too much RESt with flex because flex does not support all HTTP operations, so for doing an update I did a workaround and created a flex_update method on application_controller that is called using POST during an update, this method simple calls the default update method and everything works fine.

bcsanches
Can you provide any more details? I'm having the exact same issue, wanting to create multiple models with Flex to rails. I've tried posting XML with the nested objects, which is structured the same as the resulting XML if I did a GET on the parent object. But I'm getting an error on the rails side about expecting the child object and getting an Array instead. Sorry for the long comment but I tried to find a contact for you but couldn't.
A: 

Have you tried RubyAMF instead of XML?

raf