2
votes

Consider having a Dynamic routing page at http://localhost:4200/organizer/{organizer-id} which fetches data from a RESTful JSONAPI adapter.

organizer.js:

export default Ember.Route.extend({
  model: function(params) {
    return this.get('store').findRecord('organizer', params.organizer_id);
  }
});

Ember data pluralizes organizer into organizers when fetching data from the REST adapter. From the docs this seems to be the intended behavior, i.e. /organizers/{organizer-id}.

Yet, from their guide at https://guides.emberjs.com/v2.8.0/routing/defining-your-routes/, they seem to suggest this:

Router.map(function() {
  this.route('posts');
  this.route('post', { path: '/post/:post_id' });
});

Isn't this a contradiction? How can these routes be singular while the api endpoint above is pluralized?

1
You're confusing route paths and API endpoints. - user663031
Fill me in please. For route paths, the convention is /post/1, while it is /posts/1 for API endpoints? - Oh Chin Boon
All else being equal, yes, usually. For fun, try a model named cow and see what the API endpoint is. - user663031

1 Answers

2
votes

You are confusing the route paths and API endpoints. For the API endpoints not to rename the noun model (organizer) to use an adapter: http://emberjs.com/api/data/classes/DS.JSONAPIAdapter.html#method_pathForType

//app/adapters/organizer
import ApplicationAdapter from './application';
export default ApplicationAdapter.extend({
  pathForType: function(){
    return "organizer";
  }
});

In regards to your example using the router mapping, these are the paths of the ember application you can reach via the url bar, not the underlying API calls.