RemoteObject メソッドで渡されるパラメーターを制御するにはどうすればよいですか? このサイトからコードを直接ダウンロードして実行すると、オブジェクトを保存すると、次のパラメーター セットが返されることに気付きました。
Processing PostsController#save (for 127.0.0.1 at 2011-02-01 23:34:55) [POST]
Parameters: {0=>{"post"=>#<Post id: nil, title: "a", body: "b", created_at: nil, updated_at: nil>}, "post"=>#<Post id: nil, title: "a", body: "b", created_at: nil, updated_at: nil>}
一方、私自身のプロジェクト(基本的にそのチュートリアルと同じ手順に従う必要がありました)は、次のようなトレースを与える保存を行います
Processing CarsController#save (for 127.0.0.1 at 2011-02-01 22:34:56) [POST]
Parameters: {0=>{"car"=>#<Car id: nil, user_id: 0, name: "asdfCar", body_id: 3, theme: nil, deleted: nil, photo_file_name: nil, photo_content_type: nil, photo_file_size: nil, photo_updated_at: nil, created_at: nil, updated_at: nil>}}
明確にするために、違いは、posts コントローラーへの要求が、params[0]["post"] として 1 つと params["post"] として 1 つの投稿の 2 つのコピーを受け取るように見えることですが、私のコードは 1 つしか与えません。
RemoteObject 呼び出しを定義しているように見える唯一のコードは次のとおりです。
<mx:RemoteObject id="postRO" destination="rubyamf" endpoint="rubyamf/gateway" source="PostsController" showBusyCursor="true" fault="onFault(event)">
<mx:method name="index" result="onIndexResult(event)"/>
<mx:method name="save" result="onSaveResult(event)"/>
<mx:method name="destroy" result="onDestroyResult(event)"/>
</mx:RemoteObject>
private function onAddPost(event:MouseEvent):void
{
var post:PostVO = new PostVO();
post.title = addTitleText.text;
post.body = addBodyText.text;
post.comments = new Array();
postRO.getOperation("save").send({post:post});
}
そして、値オブジェクトの定義は
package com.unitedmindset.vo
{
[RemoteClass(alias="PostVO")]
[Bindable]
public class PostVO
{
public function PostVO()
{
}
public var id:int;
public var title:String;
public var body:String;
public var createdAt:Date;
public var updatedAt:Date;
public var comments:Array;
}
}
私自身のコードは非常に似ていますが
private function onAddCar(event:MouseEvent):void
{
var car:CarVO = new CarVO();
car.name = addNameText.text;
car.bodyId = int(addBodyIdText.text);
car.componentInstances = new Array();
carRO.getOperation("save").send({car:car});
}
<mx:RemoteObject id="carRO" destination="rubyamf" endpoint="http://localhost:3000/rubyamf/gateway" source="CarsController" showBusyCursor="true" fault="onFault(event)">
<mx:method name="index" result="onIndexResult(event)"/>
<mx:method name="save" result="onSaveResult(event)"/>
<mx:method name="destroy" result="onDestroyResult(event)"/>
</mx:RemoteObject>
<mx:RemoteObject id="componentInstanceRO" destination="rubyamf" endpoint="http://localhost:3000/rubyamf/gateway" source="ComponentInstancesController" showBusyCursor="true" fault="onFault(event)">
<mx:method name="save" result="onCreateComponentInstanceResult(event)"/>
</mx:RemoteObject>
package com.foo.vo
{
[RemoteClass(alias="CarVO")]
[Bindable]
public class CarVO
{
public function CarVO()
{
}
public var id:int;
public var userId:int;
public var name:String;
public var bodyId:int;
public var createdAt:Date;
public var updatedAt:Date;
public var componentInstances:Array;
}
}
ある種の構成設定があると思いますが (おそらく Flex で)、それが何であるかわかりません。どこを見るべきかについて何か提案はありますか?ありがとう。