我对铁路协会提出了疑问。我正在尝试为包含主题的帖子创建评论。所以我的溃败文件看起来像这样:
resources :subjects do
resources :post do
resources :comments
end
end
现在,我正在尝试在帖子的show.html.erb文件中创建一个表单,以便某人可以创建评论。我已经在rails指南中找到了这种尝试:
'posts / show.html.erb'
<%= form_for {[@post, @post.comments.build]} do |f| %>
//fill in form
<% end %>
'posts.controller.rb'
def show
@post = Post.find(params[:id])
end
但这给了我一个错误。如果您需要任何其他代码部分,请随时询问。
错误信息
ActionView::Template::Error (undefined method `post_comments_path' for #<#<Class:0x007f9a4429d5e8>:0x007f9a42c01fc8>):
8: <strong>Text:</strong>
9: <%= @post.text %>
10: </p>
11: <%= form_for ([@post, @post.comments.build]) do |f| %>
12: <p>
13: <%= f.label :text %><br>
14: <%= f.text_area :text %>
这些路径归为一组resources :subjects
,因此您的路径将为subjects_post_comments_path
,或者,如果您更喜欢使用多态路径,则该路径将为[@subjects, @post, @post.comments.build]
。
您可以运行rake routes | grep comments
以查看所有评论路线的路径。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句