【问题标题】:Controlling parameters passed in rubyamf (rails + flex)控制传入 ruby​​amf 的参数(rails + flex)
【发布时间】:2011-02-02 04:55:50
【问题描述】:

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

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

为了澄清,不同之处在于对帖子控制器的请求似乎收到了帖子的两份副本,一份作为参数[0][“post”],一份作为参数[“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 中),但我不知道它是什么。关于在哪里看的任何建议?谢谢。

【问题讨论】:

    标签: ruby-on-rails apache-flex rubyamf


    【解决方案1】:

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

    ParameterMappings.scaffolding = true
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多