Say you have two Rails models with association:
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
Thanks to ActiveModel::Serializer it is easy to send existing nested objects from Rails to Ember.js. But I can't find a way to create such nested objects in Ember and send them back to Rails for persistence. My understanding is Ember needs to send back something like:
"moo"=> {
"foos_attributes"=>{"0"=>{"name" => ...}},
"name" => ...
}
Is there a "standard" way to do that? I have seen a few "old" questions on this subject but no real solution, and since Ember has been changing so much I thought there might be a simple way to do it now (without changing the Rest Adapter itself).
Thanks a lot, PJ
I have just modified the params before handing them to create
or update_attributes
methods like this:
line_items = params[:invoice].delete(:line_items) #Ember format
params[:invoice][:line_items_attributes] = line_items
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With