Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Ember Data 2.0.0-beta1 with ActiveModel::Serializer::Adapter::JsonApi #1080

Closed
mattboldt opened this issue Aug 24, 2015 · 5 comments
Closed

Comments

@mattboldt
Copy link

Since the new ember no longer has DS.ActiveModelSerializer or DS.ActiveModelAdapter, I'm looking to switch to their new DS.JSONAPISerializer. This seems to be the best way to go, if the previous two won't be supported in the future.

Ember is expecting the data from the api to be something like

store.push({
  data: {
    id: '1', 
    type: 'user', 
    attributes: { 
      name: 'Pangratz' 
    }
  }
});

But from my rails app, with the :json_api option set to true, my api is returning user as users plural.

  data: {
    id: '1', 
    type: 'users', 
    attributes: { 
      name: 'Pangratz' 
    }
  }

Ember expects a singular model name, and as such cannot push data.

@beauby
Copy link
Contributor

beauby commented Aug 24, 2015

Right, the JSONAPI spec does not take a stance on whether the type should be singular or plural. I think there should be a global config for ActiveModel::Serializer to pluralize or not the resources.

@beauby
Copy link
Contributor

beauby commented Aug 24, 2015

I'm working on a PR to add this. Should be ready in a few minutes. Could you test it when it's out?

@mattboldt
Copy link
Author

Absolutely!

@beauby
Copy link
Contributor

beauby commented Aug 24, 2015

@mattboldt Here it is. Simply set ActiveModel::Serializer.config.jsonapi_resource_type = :singular and it should work.

@mattboldt
Copy link
Author

Yes, this worked! Thanks so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants