Jeff Rossi
Jeff Rossi

Reputation: 189

api calls have dash instead of underscore in url

At my company we are in the process of rewriting a large rails application to use the rails 5 api only mode, and I was evaluating ember.js as a possible front end, to be used on a separate application and be served by nginx. I ran into an issue in my testing on localhost and I hope you can advise a fix or patch.

// app/adapters/application.js

import DS from 'ember-data';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import config from '../config/environment';

export default DS.JSONAPIAdapter.extend(DataAdapterMixin, {
host: ${config.host},
authorizer: 'authorizer:jwt',
namespace: 'api/v1'
});

// app/models/device-profile.js

import DS from 'ember-data';

export default DS.Model.extend({
name: DS.attr('string'),
devices: DS.hasMany('device'),
assignedFlags: DS.hasMany('assigned-flag'),
deviceProfileGpios: DS.hasMany('device-profile-gpio')
});

// app/routes/device-profiles.js

import Ember from 'ember';

export default Ember.Route.extend({
model() {
return this.store.findAll('device-profile')
}
});

When I go to http://localhost:4200/device-profiles I get the following 404 error in my rails console

Started GET "/api/v1/device-profiles" for ::1 at 2017-04-30 08:10:30 -0400

ActionController::RoutingError (No route matches [GET] "/api/v1/device-profiles"):

Is there some setting that I am missing or is this a bug?

Upvotes: 1

Views: 703

Answers (1)

Jeff Rossi
Jeff Rossi

Reputation: 189

Managed to find the answer in the issues on ember data github site

I added this to my application adapter

pathForType: function(type) {
    var underscored = Ember.String.underscore(type);
    return Ember.String.pluralize(underscored);
}

Upvotes: 1

Related Questions