Search code examples
javascriptember.jsember-rails

EmberJS console error- Error while loading route: undefined


I am a beginner in EmberJS. It would be great if you can give a detailed explanation. I have api end point for fetching the products which expects the GET request to the following url-

/api/products?date=2014-09-16&meal_type=2

Here, date and meal_type are the query parameters. My router.js looks like this-

    App.Router.map(function() {
      this.resource('products', { path: '/products/date/:date/meal/:mealType'} );
    });

    App.Router.reopen({
      location: 'history'
    });

The reason for this dynamic route is that the url of my application appears to be in the same format.

routes/product.js looks like-

    App.ProductsRoute = Ember.Route.extend({
      model: function(params) {
        return this.store.findQuery('product', {date: params.date, meal_type: params.mealType});
    },

      queryParams: {
        date: {
          refreshModel: true
        },
        mealType: {
          refreshModel: true
        }
      },

});

controller/products_controller.js

    App.ProductsController = Ember.ArrayController.extend({
      queryParams: ['date', 'meal_type'],
      date: null,
      meal_type: null,

      products: function() {
        return this.get('model.content');
      }.property()

I am getting an error on browser console-

Error while loading route: undefined

This appears to be in line ember.js?body=1:3522.

Any help would be highly appreciated. Thanks


Solution

  • After doing a lot of research on the error, I figured out the inconsistency in database. I resolved the error by restoring the consistent database dump.

    Conclusion: EmberJS expects data to be consistent. Otherwise, it can raise errors which are difficult to debug.