1

我正在使用nested_formacts_as_commentable

我希望能够向问题或解决方案添加评论。一个问题有很多解决方案(想想stackoverflow,你不会错的)。

对于下面的嵌套表单,我如何将 Solution.comments 传递给 link_to_add 帮助器(请参阅#comment 4th line from end)?目前,在特定解决方案下方输入的评论被分配给父问题(提交时),即使帮助程序嵌入在解决方案字段的 fields_for 中。

注意:如果我在 Rails 控制台中通过 Solution.comments.create 添加评论,则当我重新显示时,评论会在解决方案下正确显示,所以我很确定这只是我需要修复的 link_to_add 帮助器调用。

有人有什么想法吗?

这是(haml)嵌套形式

= nested_form_for @question, :html => { :class => 'form' } do |f|
  .control-group
    = f.fields_for :comments do |comment_form|
      = comment_form.text_field :comment
      = comment_form.link_to_remove "Remove Comment"
    %p= f.link_to_add "Add a comment", :comments
  .form-actions
    = f.submit nil, :class => 'btn btn-primary'
  .control-group
    = f.fields_for :solutions do |solution_form|
      = solution_form.text_area :solution
      = solution_form.link_to_remove "Remove Solution"
      %br
      = solution_form.fields_for :comments do |comments_form|
        = comments_form.text_field :comment
        = comments_form.link_to_remove "Remove Comment"
      # I believe the below line is the problem
      %p= solution_form.link_to_add "Add Comment", :comments
    %p= f.link_to_add "Add Solution", :solutions
  .form-actions
    = f.submit nil, :class => 'btn btn-primary'
4

0 回答 0