it seems that i am not setting up my model hook in my router correctly because my data is rendering in the template. but maybe there is something else that i'm missing
here is my router
Router.map(function() {
this.resource('movies', function() {
this.route('show', { path: ':movie_id'}, function() {
this.resource('rewrites', function() {
this.route('show', { path: ':id'});
this.route('new');
this.route('edit');
});
});
this.route('edit', { path: ':movie_id/edit'});
this.route('new');
});
});
in my index template for rewrites below, templates/rewrites/index.hbs, i need to show all the rewrites that are for one particular movie
{{outlet}}
{{link-to 'Add a New Rewrite' 'rewrites.new'}}
<table class="table table-bordered">
<thead>
<tr>
<th>Name</th>
<th>Script</th>
<th>Author</th>
<th></th>
</tr>
</thead>
<tbody>
{{#each rewrite in movie}}
<tr>
<td>
{{rewrite.name}}
</td>
<td>{{rewrite.script}}</td>
<td>{{rewrite.author}}</td>
<td>{{link-to 'Edit this Rewrite' 'rewrites.edit' this}}</td>
<td><a href="#" {{action 'delete' rewrite}}>Delete</a></td>
</tr>
{{/each}}
</tbody>
</table>
my model setup in my route, routes/rewrites/index.js, is
model: function() {
var movie = this.modelFor('movies.show');
return this.store.findAll('rewrite', { movie:movie });
},
i've tried many things for the model, also tried
return this.store.findAll('rewrite');
either way the template is found and rendered, but there is no data after creating rewrite 2, i've then tried
return this.store.find('rewrite', 2);
and that does not render any data either.
UPDATE:
the router above is correct. the templates/rewrites/index.hbs above should be {{#each rewrite in model}}
and the model hook should be
model: function() {
return this.modelFor('movies.show').get('rewrites');
},
also, this app's api is a rails app. and in the rails serializer for movie, i needed to add the has_many to sideload rewrites as in:
class MovieSerializer < ActiveModel::Serializer
attributes :id, :title, :director, :releaseDate, :cast, :description, :imageUrl
has_many :rewrites, embed: :ids, include: true
end