I have a simple Ember 2.4 application. Here's the relevant code
../models/invitation.js
import DS from 'ember-data';
export default DS.Model.extend({
email: DS.attr('string')
});
../controllers/index.js
import Ember from 'ember';
export default Ember.Controller.extend({
emailAddress: '',
actions: {
saveInvitation() {
const email = this.get('emailAddress');
const newInvitation = this.store.createRecord('invitation', {
email: email,
});
newInvitation.save();
}
}
});
When I trigger the saveInvitation
action, my Rails backend does not receive any parameters. The right action/controller receives the request but the only parameters are {action: "create", controller: "invitations"}
.
Am I missing something? Shouldn't the parameters include the invitation with the email?
It seems that the default Ember adapter sends a content type application/vdn.api+json
which is not automatically registered by Rails and parse the JSON arguments.
A fix for this was to register the right mime types under rails config
api_mime_types = %W(
application/vnd.api+json
text/x-json
application/json
)
Mime::Type.unregister :json
Mime::Type.register 'application/json', :json, api_mime_types
See https://github.com/rails-api/active_model_serializers/issues/1027