I'm new to Rails and web programming, and can't seem to accomplish this simple task. I have a post with several comments ( something like reddit or HN ). I want to add a new comment from the post view. The problem is that the comment is created by the create method of the Comment Controller, and it doesn't know what post it belongs to. Do I need to use a posts_helper to store the current post?
问问题
140 次
1 回答
4
Read the getting started guide on the rails guides site. It goes through creating a blog with comments.
You need to scope the creation of comments to the post that is being commented on. e.g. @post.comments.create(params[:comment])
. The getting started guide will discuss all this.
于 2012-09-15T13:18:57.937 回答