Ember and Ruby on Rails Associated Record Problems
I’ve been learning Ember recently, using Rails as backend. Not having this one line in my application caused me a world of hurt: App.ApplicationSerializer = DS.ActiveModelSerializer.extend({}); I was going through all kinds of pain to force Ember to load associations and it was making a geniune mess of my application and leaving me a bit baffled with Ember.
Ember by default expects an association conveyed as projects: [1,2,3] as opposed to a typical Rails association project_ids: [1,2,3]
Ember => app/app.js:
App.ApplicationSerializer = DS.ActiveModelSerializer.extend({});
Rails => app/serializers/client_serializer.rb:
class ClientSerializer < ActiveModel::Serializer
embed :ids
has_many :projects
Ember => app/models/client.coffee:
Client = DS.Model.extend
projects: DS.hasMany('project', {async: true})
I am available for Ruby on Rails and Ember consulting work – get in touch to learn more.