3

pls は、繭の 'link_to_add_association' を html_options と共に使用する例を示しています。 https://github.com/nathanvda/cocoon

ドキュメントには次のように記載されています。

html_options: extra html-options (see link_to) There are two extra options that allow to conrol the placement of the new link-data:

    data-association-insertion-node : the jquery selector of the node
    data-association-insertion-position : insert the new data before or after the given node.

しかし、「要素を追加」リンクの直前に部分的に挿入したい場合、どうすればよいかわかりません。親のdivが始まった直後ではありません。これはうまくいきません:

<%= link_to_add_association "add element", f, :production_years, :position => "after_all" %>

4

2 に答える 2

9

それは少しあいまいであることを認めます。おそらく、コードで例を提供する必要があります。

あなたapplication.jsは次のように書くべきです:

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

a.add_fieldsクリック可能なリンクを選択する場所。最近、readme を更新して、挿入の処理方法をより適切に説明しました。

お役に立てれば。

于 2011-10-15T14:14:58.720 に答える
6

データ属性を使用してそれを行いたい場合は、次のことができます。

<%= link_to_add_association 'Add Item', f, :items, :data => {"association-insertion-method" => "before" } %>
于 2012-10-26T22:57:12.673 に答える