【问题标题】:Rails3-amf and bringing an association to amfRails3-amf 并为 amf 带来关联
【发布时间】:2011-01-18 19:47:23
【问题描述】:

我正在从 WebORB 更改为 Warhammerkids Rails3-amf - 不错的选择,甚至还有一些未解决的问题。其中一个问题是,我如何从关联到数组中获取记录,然后将其发送回 Flex-Application。 在 WebORB 中,控制器的方法如下所示:

 def getClients(clientFilter,myMandant)
     clients = Client.find(:all, :conditions => {:account_id => myMandant}, :include => [:addresses, :contacts, :proofs])
  end

在 Rails3-amf 中我有类似的结构:

def getClients()
     @clients = Client.find(:all, :conditions => {:account_id => params[1]}, :include => [:addresses, :contacts, :proofs])
    respond_with(@clients) do |format|
       format.amf { render :amf => @clients}
  end

使用此代码,我将所有正确键入的客户端对象作为数组返回,但没有来自“:include”参数的记录。 我该如何处理??

我还尝试了另一种方法:

....
respond_with(@clients) do |format|
       format.amf { render :amf => @clients.to_amf(:include => [:addresses, :contacts, :proofs])}
....

通过此尝试,我收到一条错误消息“未定义方法 to_amf for #.

感谢您的帮助。

【问题讨论】:

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


    【解决方案1】:

    我不了解 rail3-amf,但您可能会发现值得看看 restfulx - https://github.com/dima/restfulx/tree/rails3

    它由一个用于 rails 的库和一个用于 flex 的库组成。它支持通过json、xml或amf进行数据传输。

    用于处理模型的 actionscript api 也非常好:

    var user:User = new User();
    user.first_name = "Ed";
    user.create();
    

    它还可以跟踪 Rails 关联等:

    trace(user.account.title);
    

    在此处查看更多用法 - https://github.com/dima/restfulx_framework/wiki/Working-with-RestfulX-Models

    【讨论】:

      猜你喜欢
      • 2011-04-28
      • 1970-01-01
      • 1970-01-01
      • 2010-12-02
      • 2012-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多