控制 ruby​​amf (rails + flex) 中传递的参数

发布于 2024-10-15 14:01:20 字数 3535 浏览 0 评论 0原文

如何控制在 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>}}

为了澄清,差异是对帖子控制器的请求似乎收到了帖子的两份副本,一份作为 params[0]["post"],一份作为 params["post"],而我的代码只提供一份。

似乎定义 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 中),但我不知道它是什么是。关于去哪里看有什么建议吗?谢谢。

How do I control what parameters are passed in a RemoteObject method? I noticed that when I directly download and run the code from this site, saving an object results in the following parameter set being passed back:

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>}

whereas my own project (which basically involved following the same steps as in that tutorial) makes saves that give traces like

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>}}

To clarify, the difference is that the requests to the posts controller seem to receive two copies of the post, one as params[0]["post"] and one as params["post"], whereas my code only gives one.

The only code that seems to define the RemoteObject call is

<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});
        }

and then the value object definition is

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;

    }
}

while my own code looks damn similar with

    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;
    }
}

I assume there is some sort of configuration setting (presumably in Flex), but I can't figure out what it is. Any suggestions on where to look? Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

送你一个梦 2024-10-22 14:01:20

解决了我的问题。在 ruby​​amf_config.rb(在 config 文件夹中)中,需要添加以下行:

ParameterMappings.scaffolding = true

所以,是的,设置是在 Rails 中而不是在 Flex 中。我猜rails启动了,然后当flash启动时,它会询问rails它想要什么格式的响应(这是有道理的,因为它还必须处理ClassMappings),然后flash使用商定的格式发布到rails应用程序。

Solved my problem. In rubyamf_config.rb (in the config folder), needed to add the line:

ParameterMappings.scaffolding = true

So, yeah, the setting was in rails rather than in flex. I guess rails starts up, then when flash starts up it asks rails what format it wants responses in (which makes sense because it also has to deal with the ClassMappings), then flash posts to the rails app using the agreed-upon format.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文