将 form_for 与 Awesome Nested Set 一起使用
我有一个启用了acts_as_nested_set的注释模型,但是当我尝试执行类似的操作(对于嵌套注释)时,我收到错误“未找到comment_comments_path”,大概是因为默认路径不适用于Awesome Nested Set。我该如何解决这个问题?
<%= form_for([@comment, @comment.children.build]) do |f| %>
<%= f.text_area :content, :placeholder=>'What do you think?'%>
<%= f.submit 'Submit Reply'%>
<% end %>
我也尝试过这个:
<%= form_for(@comment) do |f| %>
<% @comment.children.each do |sub| %>
<%= f.fields_for :children, sub do |child| %>
<%= child.text_area :content, :placeholder=>'What do you think?'%>
<%= f.submit 'Submit Reply'%>
<% end %>
<% end %>
<% end %>
但它没有生成一个文本框供我输入。
I have a Comment model with the acts_as_nested_set enabled, but when I try to do something like this (for nested comments), i receive the error "comment_comments_path not found", presumably because the default pathing doesn't work with Awesome Nested Set. How do I get around this?
<%= form_for([@comment, @comment.children.build]) do |f| %>
<%= f.text_area :content, :placeholder=>'What do you think?'%>
<%= f.submit 'Submit Reply'%>
<% end %>
I also tried this:
<%= form_for(@comment) do |f| %>
<% @comment.children.each do |sub| %>
<%= f.fields_for :children, sub do |child| %>
<%= child.text_area :content, :placeholder=>'What do you think?'%>
<%= f.submit 'Submit Reply'%>
<% end %>
<% end %>
<% end %>
but it didn't generate a textbox for me to type in.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你非常接近,是的,你必须先构建它,然后为其添加字段,所以:
这将为所有现有的子项+新的子项提供一个表单。如果您只想要一个新孩子的表格,那么您会需要这个:
You're very close, yeah you have to build it first then have fields for, so this:
This will have a form for all existing children + the new one. If you want only a form for a new child then you'll want this instead: