[Update]
Thanks for the help so far.
I've been able to create a new Post record with an embedded Comment record with static data. Via this method:
App.CommentsController = Ember.ArrayController.extend({
needs: "post",
actions: {
addComment: function() {
var post = App.Post.create({
title: 'static post'
});
post.get('comments').create({
message: 'static message'
});
post.save();
}
}
});
But I'm falling short figuring out how to retrieve the current Post via the CommentsController or Route in order to create Comment records on an already existing Post.
After searching and sifting through random SOs and articles, I've tried an array of methods to call the current Post but still no dice.
I've tried setting var post = App.Post.create
to:
var post = App.Post.find(),
var post = this.get('controllers.post.model'),
var post = this.get('controllers.post.content'),
var post = this.get('controllers.post'),
var post = this.get('post'),
I've also set my CommentsController
to have needs: "post"
.
I've also tried adding:
App.CommentsRoute = Ember.Route.extend({
afterModel: function() {
this.set('post', this.modelFor('post'));
}
});
I read a piece that stated actions should be defined in the routes as well, would I need to define my addComment
function in the PostRoute
?
I'm wondering if I need to use var post = App.Post.find(post)
or something of that nature.
Am I on the right track here? Feels like I'm taking shots in the dark at an elephant in a broom closet and still missing...