9

関連付けられた 2 つの Rails モデルがあるとします。

class Foo < ActiveRecord::Base
  attr_accessible :name

  belongs_to :moo
end

class Moo < ActiveRecord::Base
  attr_accessible :name

  has_many :foos
  accepts_nested_attributes_for :foos
end

ActiveModel::Serializer のおかげで、ネストされた既存のオブジェクトを Rails から Ember.js に簡単に送信できます。しかし、Ember でそのようなネストされたオブジェクトを作成し、永続化のために Rails に送り返す方法を見つけることができません。私の理解では、Ember は次のようなものを返送する必要があります。

"moo"=> {
   "foos_attributes"=>{"0"=>{"name" => ...}},
   "name" => ...
}

それを行う「標準的な」方法はありますか?この件に関していくつかの「古い」質問を見てきましたが、実際の解決策はありません.Emberは非常に多くの変更を行っているため、(Rest Adapter自体を変更せずに)簡単な方法があるのではないかと思いました.

どうもありがとう、PJ

4

1 に答える 1

2

create次のようなupdate_attributesメソッドに渡す前に、パラメータを変更しました。

  line_items = params[:invoice].delete(:line_items) #Ember format
  params[:invoice][:line_items_attributes] = line_items
于 2013-03-20T16:13:42.933 に答える