1

私はnested_formacts_as_commentableを使用しています

質問または解決策のいずれかにコメントを追加できるようにしたい。質問には多くの解決策があります(stackoverflowを考えれば、間違いはありません)。

以下のネストされたフォームの場合、Solution.commentsをlink_to_addヘルパーに渡すにはどうすればよいですか(#commentの最後から4行目を参照)。現在、特定のソリューションの下に入力されたコメントは、ヘルパーがソリューションフィールドのfields_forに埋め込まれている場合でも、親の質問(送信時)に割り当てられます。

:レールコンソールの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