On the Rails API side, I have the following 2 models:
class Grower < ActiveRecord::Base has_many :addresses, as: :addressable accepts_nested_attributes_for :addresses end class Address < ActiveRecord::Base belongs_to :addressable, polymorphic: true end
as well as the Growers controller, which returns and can create / update Growers with the built-in attributes of Addresses. I also have an Address controller with the correct routing so Addresses can be viewed / created / updated for a specific Grower. The latter is more likely an "in-case", and I'm not sure that I will need to return / update / create addresses as a separate payload.
I'm starting to try to combine the Ember application, which will allow me to view / edit / create Grower simultaneously with its address (addresses). Can someone point me to an existing real or sample application that does this? I will publish my code while I go, but I already have an idea of ββsome areas where I will encounter difficulties:
Rails returns / expects nested parameters called addresses_attributes . Amber, I'm sure, is not using this convention. What is the best approach to resolving this?
Due to the polymorphic association (objects other than Grower can be addressable), on the API / Address side, Rails uses addressable_id in combination with addressable_type to get the correct assign_to object. In this example, addressable_type will be "Grower", and addressable_id will be the value of grower_id. How can I translate this on the Ember side?
UPDATE:
I have earned at least a couple of different ways. My preferred solution, at least for this particular case, is in the answer section.
source share