mercredi 4 février 2015

How to create nested ember route when each parent has same child ids?

I am using ember-cli from a rails api to try and display the lecture template of a nested route. This is my router:



Router.map(function() {
this.route('home');
this.resource('courses', function() {
this.resource('course', { path: '/:course_id' }, function() {
this.resource('lecture', { path: '/lecture/:lecture_id' });
});
});
});


I have no trouble displaying individual lectures in a course template using:



{{#each lecture in lectures}}
{{#link-to 'lecture' lecture classNames='list-group-item'}}{{lecture.name}}{{/link-to}}
{{/each}}


So I can see in the ember inspector that my courses and lecture data loads with no troubles. The problem is that when I click on that link, it displays the right URL up top but the page doesn't change.


Course Model:



export default DS.Model.extend({
name: DS.attr('string'),
lectures: DS.hasMany('lecture', {async: true})
});


Lecture Model:



export default DS.Model.extend({
name: DS.attr('string'),
level: DS.attr('string'),
course: DS.belongsTo('course')
});


My ideal scenario would be for the route to point to the level parameter since each course can have lecture levels 1-8, but I am not sure how to even get it to display the ember id because this route does not work:


Lecture Route:



import Ember from 'ember';

export default Ember.Route.extend({
model: function(params) {
return this.store.find('lecture', params.lecture_id);
}
});


Can anyone give me guidance on how to make this nested ember route possible? Thanks so much!





Aucun commentaire:

Enregistrer un commentaire