Search code examples
restember.jsember-dataember-cli

Ember-cli , how do i change rest call on fly in the rest adapter


Im working on ember-cli, how do i change rest call on fly in the rest adapter. If i use path params not query params?for example:

export default DS.RESTAdapter.extend({   
  namespace:'res/v1/users/id',   
  pathForType: function() {  
       return Ember.String.underscore("friends");},});

Based on the user selection from dropdown we get the "id", using the id I need to get user friends from the database. Could you please suggest a better way to do. My aapplication supports pathparams not the query params


Solution

  • I have created a variable in enviroment.js 'userId'. When ever i select a user i set config.userId in the controller to the corresponding Id.

    config.userId=this.get('selectedUser');
    

    In pathforType of adapter I used this varible

     pathForType: function() {
        return Ember.String.underscore(config.userId+"/friends");
    }
    

    you just need to add an import statement

    import config from '../config/environment';
    

    Please suggest me if anyone get to know better way. Thanks all for your responses