Search code examples
javascriptember.jsember-cli

Error Route Not Found on RestAdapter


I have this route configuration on my router.js

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

var Router = Ember.Router.extend({
  location: config.locationType
});

Router.map(function() {
  this.route('about');
  this.resource('posts');
});

export default Router;

and inside my routes folder I have this posts.js

import Ember from 'ember';

export default Ember.Route.extend({
  model: function() {
      return this.store.find('post');
    }
});

and inside my model folder I have this ember-data model

import DS from 'ember-data';

export default DS.Model.extend({
    title: DS.attr()
});

And here's my Adapter

import DS from 'ember-data';

export default DS.RESTAdapter.reopen({
  namespace: 'api'
});

However whenever I access the resource(localhost:4200/posts) I receive this error

Error while processing route: posts Not Found ember$data$lib$adapters$rest$adapter$$default<.ajaxError@http://localhost:4200/assets/vendor.js:60763:35
ember$data$lib$adapters$rest$adapter$$default<.ajax/</hash.error@http://localhost:4200/assets/vendor.js:60838:37
jQuery.Callbacks/fire@http://localhost:4200/assets/vendor.js:3350:10
jQuery.Callbacks/self.fireWith@http://localhost:4200/assets/vendor.js:3462:7
done@http://localhost:4200/assets/vendor.js:9518:1
.send/callback@http://localhost:4200/assets/vendor.js:9920:8

NOTE:

I've also set up a mock http rest server using this command ember g http-mock post


Solution

  • Found the solution myself. Turns out the the mock I needed to create a mock with the same name as my resource that's configured in the router.js

    so I created a new http mock using this one

    ember g http-mock posts
    

    in my case, Turns out that the route specified should be the same as the JSON you are retrieving.