0
我已经嵌套在其嵌套在游戏的帖子评论。我不知道如何添加评论。我收到一个未定义的方法。三重嵌套问题的意见
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
谢谢,这工作! 我结束了使用 def create - @ post = Post.find(params [:post_id]) - @ comment = -post.comments.create(params [:comment]) - @ game = - @ post .game_id redirect_to的game_post_path( - @游戏, - @后) 结束 的重定向,因为game_id没有得到传递给柱控制器。 – Jason 2012-08-09 15:02:01