如何在所有已保存字段的顶部添加新的link_to_ad_association空白表单,而不是在末尾添加


= form_for [:update, @user_comments], url: [:udpate_comments, :update, @user] do |f|
= f.fields_for :user_comments do |comment_fields|
= render 'user_comment_fields', f: comment_fields
= link_to_add_association "Add Comment", f, :user_comments, class: 'btn btn-secondary'
= submit_button(f)

我希望"添加评论"按钮在顶部,新的评论空白表单应该添加在所有评论的顶部。就像这样:

添加评论按钮

【空白评论表】

[评论3]

[评论2]

[评论1]

现在,新的评论空白表单被添加到所有评论的末尾。

使用解决问题

$(document).ready(function() {
$("#owner a.add_fields").
data("association-insertion-method", 'before').
data("association-insertion-node", 'this');
});

最新更新