I have this jsfiddle . Everything works, except that I cannot create a new comment by submitting a comment form. when i submit the form, the console shows undefined . I hope that in order to achieve this, you need to pick up the existing post and then create a comment related to this post. Thus, the flow of events, the user clicks on the message , then select a specific header to display it, and then click add comment to comment on this article. It is important to note that for now, clicking the add comment button will return undefined .
The corresponding section of code using addComment and save methods.
EmBlog.CommentNewController = Em.ObjectController.extend({ needs: ['postsShow'], isAddingNew: false, addComment: function(body){ post = this.get('controllers.postsShow.model'); store = post.get('transaction'); store.createRecord(EmBlog.Comment, {body: body}); this.set('isAddingNew', true); }, save: function(){ console.log(this.store.commit()); } });
** Corresponding section from the handle template
<script type='text/x-handlebars' data-template-name='comment/new'> {{#if controller.isAddingNew}} <form {{action save on='submit'}}> {{view Ember.TextArea valueBinding="body" placeholder="body"}} <button type="submit"> save comment </button> </form> {{/if}} <br/> <div> <button {{action addComment}} {{bindAttr disabled="isAddingNew"}}> Add Comment </button> </div> </script>
The comment form is submitted via 'posts / show template' using render
<script type="text/x-handlebars" data-template-name="posts/show"> <p> Comments</p> {{render 'comment/new' comments}} </script>
source share