Update user when using singular resource


#1

My API is using singular resource - http://guides.rubyonrails.org/routing.html#singular-resources

And i’m using the following code in a service to load the current user:

import Ember from ‘ember’;

export default Ember.Service.extend({
  session: Ember.inject.service(),
  store: Ember.inject.service(),

  load() {
    if (this.get('session.isAuthenticated')) {
      return this.get('store').queryRecord('user', {
        me: true
      }).then((user) => {
        this.set('user', user);
      });
    }
    return Ember.RSVP.resolve();
  }
});

SO in my routes dashboard/users/update, i just need return the currentUser in order to show the information in the inputs, allowing the users to update something:

import Ember from 'ember';

export default Ember.Route.extend({
  currentUser: Ember.inject.service(),

  model() {
    return this.get('currentUser.user');
  }
});

But, when i try to use the save method, to make the request to the API, the request url is users/:id, and this endpoint doesn’t exist in my backend, since i’m using singular resource. Is it possible to overwrite this behaviour??

Thank you.


#2

Yes, you can override this behavior in your adapter. Check out the urlForUpdateRecord method in the adapter: https://emberjs.com/api/data/classes/DS.RESTAdapter.html#method_urlForUpdateRecord