2

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

3
  • try this: change /// this.resource('products', { path: '/products/date/:date/meal/:mealType'} );/// to this.resource('products');. As I suspect, the path is just to specify the url, and because you are routing with that url thus having such error. Try to log the params with the code I included, if the params is visible then you can go ahead and do whatever you are doing in your route. Hope it helps. Commented Sep 16, 2014 at 0:53
  • The url including path has been set for dynamic routing. I tried your solution but got an error Uncaught Error: Assertion Failed: Error: Assertion Failed: The URL '/products/date/2014-09-16/meal/1' did not match any routes in your application Commented Sep 16, 2014 at 5:13
  • of course, it would return an error. If you want a route with that url. It should be something like this: this.resource('products', function(){ this.resource('date', 'path': '/:products_date', function(){ this.resource('meal', 'path': '/:products_meal') }) }); Commented Sep 17, 2014 at 1:02

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.