首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >控制在rubyamf中传递的参数(rails + flex)

控制在rubyamf中传递的参数(rails + flex)
EN

Stack Overflow用户
提问于 2011-02-02 12:55:50
回答 1查看 377关注 0票数 1

如何控制在RemoteObject方法中传递哪些参数?我注意到,当我直接从this site下载并运行代码时,保存对象会导致传递回以下参数集:

代码语言:javascript
复制
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>}

而我自己的项目(基本上包括遵循与该教程中相同的步骤)进行保存,以提供如下跟踪

代码语言:javascript
复制
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控制器的请求似乎接收了两个post副本,一个作为params,另一个作为params"post",而我的代码只提供了一个。

唯一可以定义RemoteObject调用的代码是

代码语言:javascript
复制
<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});
        }

然后,值对象定义为

代码语言:javascript
复制
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;

    }
}

虽然我自己的代码看起来非常类似于

代码语言:javascript
复制
    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中),但我不知道它是什么。关于去哪里找有什么建议吗?谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-02-04 00:40:19

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

代码语言:javascript
复制
ParameterMappings.scaffolding = true

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4870909

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档