Sri
Sri

Reputation: 5845

Ember .transitionToRoute and currentModel issue

My route is defined:

this.resource("visitor", {path: ":id"});

When I visit the page via the URL /12345, the value of this.currentModel is

{id: "12345"}

but when I this.transitionToRoute("visitor", "12345") from another (parent) controller, the value of this.currentModel is

"12345"

I also get this exception:

Uncaught Error: assertion failed: Path '12345' must be global if no obj is given.

Any ideas what's going on?

More code:

App.VisitorRoute = Ember.Route.extend({
  model: function (params) {
    return {id: params.id};
  },
  setupController: function() { ... }
}

Upvotes: 1

Views: 5633

Answers (2)

Teddy Zeenny
Teddy Zeenny

Reputation: 3971

You need to explain to the router how to translate your model into a URL, for that you need to override serialize.

App.VisitorRoute = Ember.Route.extend({
  model: function (params) {
    return {id: params.id};
  },
  serialize: function(model) {
    return model;  
  }
});

After that pass the model with the transition:

this.transitionToRoute('visitor' , { id: 12345 });

Upvotes: 3

ianpetzer
ianpetzer

Reputation: 1838

When you call this.transitionToRoute() you need to pass in the route and the model as arguments, so instead of this.transitionToRoute("visitor", "12345"), rather use this.transitionToRoute("visitor", vistorModel)

Upvotes: 2

Related Questions