// app/router.js
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType
});
Router.map(function() {
this.route('questions');
this.route('question', { path: "/questions/:question_id" });
});
// app/routes/questions.js
import Ember from 'ember';
import AuthenticatedRouteMixin from 'ember-simple-auth/mixins/authenticated-route-mixin';
export default Ember.Route.extend(AuthenticatedRouteMixin, {
correct: "",
wrong: "",
model () {
return this.store.find("question").then(questions => {
return this.store.find("key", this.get("session.data.authenticated.key")).then(key => {
this.set("correct", key.get("correct"));
this.set("wrong", key.get("wrong"));
return key.get("questions");
});
});
},
afterModel (model, transition) {
this.controllerFor("question").set("key", this.get("session.data.authenticated.key"));
model = model.filter(item => {
return this.get("correct").indexOf(item.id) === -1 && this.get("wrong").indexOf(item.id) === -1;
});
this.transitionTo("question", model.get("firstObject"));
}
});
//app/routes/question.js
import Ember from 'ember';
export default Ember.Route.extend({
model (params) {
return this.store.find("question", params.question_id);
},
setupController (controller, model) {
controller.set("model", model);
}
});
//app/controllers/question.js
import Ember from 'ember';
export default Ember.Controller.extend({
key: "",
option: "",
actions: {
submitQuiz () {
this.store.findRecord("key", this.get("key")).then(key => {
key.set("answer", this.get("option"));
key.save();
}).then(() => {
this.transitionToRoute("questions");
});
},
selected (option, elm) {
this.set("option", option);
Ember.$(".question_container").find(".selected").removeClass("selected");
Ember.$("#".concat(elm)).addClass("selected");
}
}
});
However, this.transitionToRoute(“questions”) in app/controllers/questions.js is being aborted in the middle of transition. Any idea why that’s happening??? And is there a way to force transition???