我在嵌套在游戏中的帖子中嵌套了评论。我一生都无法弄清楚如何添加评论。我得到一个未定义的方法。
Showing /Users/***/Documents/TestRoutes/app/views/posts/show.html.erb where line #31 raised:
undefined method `post_comments_path' for #<#<Class:0x007fb2159834a0>:0x007fb215980228>
Extracted source (around line #31):
28: <% end %>
29:
30: <h2>Add a comment:</h2>
31: <%= form_for([@post, @post.comments.build]) do |f| %>
32: <div class="field">
33: <%= f.label :commenter %><br />
34: <%= f.text_field :commenter %>
<%= form_for([@post, @post.comments.build]) do |f| %>
resources :games do
resources :posts do
resources :comments
end
end
def create
@post = Post.find(params[:post_id])
@comment = @post.comments.create(params[:comment])
redirect_to game_post_path(@post)
end
class Comment < ActiveRecord::Base
belongs_to :post
attr_accessible :body, :commenter
end
class Post < ActiveRecord::Base
attr_accessible :post, :title, :game_id, :user_id
belongs_to :user
belongs_to :game
has_many :comments