2011-09-24 2 views
3

pls는 html_options와 함께 Cocoon의 'link_to_add_association'을 사용하는 예를 보여줍니다.레일 3.1. Cocoon link_to_add_association 예가 필요합니다.

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. 

하지만 난 그냥 내 "요소를 추가"링크를하기 전에 부분적으로 삽입하려는 경우 내가, 무엇을 이해할 수 없다 : https://github.com/nathanvda/cocoon

문서는 말한다. 부모의 div 시작 직후가 아닙니다. 이없는 거 일 :

<퍼센트 = link_to_add_association "요소를 추가", F : production_years, => "after_all"%이>

답변

9

내가 즉이 조금 애매한 인정할 것이다 위치, 코드에 예제를 제공해야합니다. 에서

당신의 application.js 당신이 뭔가를 작성해야 : a.add_fields 당신의 클릭 가능한 링크를 선택합니다

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

. 나는 삽입이 어떻게 처리 될 수 있는지에 대한 더 나은 설명과 함께 readme를 최근에 업데이트했다.

희망이 도움이됩니다.

+0

한이 -이 많이 필요했다. 고맙습니다! – Jordan

+0

나는 https://github.com/nathanvda/cocoon#control-the-insertion-behaviour (또는 적어도 이전보다 좋음)이 잘 문서화되었다고 생각했다. – nathanvda

+0

그렇습니다. 어떻게 든 나는 그것을 놓쳤다. 그것을 지적 주셔서 감사합니다. – Jordan

5

당신은 데이터-속성 당신이 할 수있는 사용하여 수행 할 경우

<%= link_to_add_association 'Add Item', f, :items, :data => {"association-insertion-method" => "before" } %> 
+0

': data =>'를 사용하는 경우 jquery 함수를 사용하여 association-insertion-node를 가져올 수 없습니다. 다음과 같이 : 'data ("association-insertion-node", function (link) { return link.closest ('행') 다음 ('행'). ' – DrevanTonder