I'm building my first ember app (ember-cli), and am confused.
I have the following route, which successfully chooses a view based on an attribute in the model:
import Ember from 'ember';
export default Ember.Route.extend({
afterModel: function(tournament) {
var state = tournament.get('state');
if (state === 0) {
this.transitionTo('tournaments.setup', tournament);
} else if (state === 1) {
this.transitionTo('tournaments.play', tournament);
} else if (state === 2) {
this.transitionTo('tournaments.complete', tournament);
}
}
});
Then I wanted to add some functionality to the tournaments.setup
page. So I added a controller (at tournaments/controllers/setup.js
:
import Ember from 'ember';
export default Ember.Controller.extend({
actions: {
start: function() {
var that = this;
var model = this.get('model');
model.set('state',1);
model.save().then(function(tournament) {
that.transitionToRoute('tournaments.play', tournament);
});
}
}
});
This worked, in the sense of enabling the start
action that I had created to change the model and redirect to the desired route. But this also had the effect of keeping the model from making it to the setup.hbs
template, shown below:
<h3>{{name}}</h3>
<h4>Setup!</h4>
<p>{{state}}</p>
<p>{{eventDate}}</p>
<button {{action "start"}} class="btn btn-primary">Start</button>
The attributes of the model are shown if the controllers/tournaments/setup.js
file does not exist. Somehow creating this file, which is not called when I go to the setup
route, prevents the model from reaching the template.
I've also tried explicitly defining the route setup.js
route, but that didn't help.
I'm using the FixtureAdapter, if that matters. Any ideas? Is there a concept I'm missing?