Isnor Creative
Isnor Creative Blog
Ruby, Ruby on Rails, Ember, Elm, Phoenix, Elixir, React, Vue

Jan 6, 2015

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.

Gordon B. Isnor

Gordon B. Isnor writes about Ruby on Rails, Ember.js, Elm, Elixir, Phoenix, React, Vue and the web.
If you enjoyed this article, you may be interested in the occasional newsletter.

I am now available for project work. I have availability to build greenfield sites and applications, to maintain and update/upgrade existing applications, team augmentation. I offer website/web application assessment packages that can help with SEO/security/performance/accessibility and best practices. Let’s talk

comments powered by Disqus