· 1 min read

Screencast: Formulare mit verschachtelten Modellen Teil 2

Download:

Download (15.9 MB, 12:40) alternative download for iPod & Apple TV (20.2 MB, 12:40)

Resourcen:

Quellcode:

[html]

<%= link_to_add_fields “Add Question”, f, :questions %>

<%= link\_to\_remove\_fields "remove", f %> ...

<%= link\_to\_add\_fields "Add Answer", f, :answers %>

<%= link\_to\_remove\_fields "remove", f %> \[/html\]

[javascript] // application.js function remove_fields(link) { $(link).previous(“input[type=hidden]“).value = “1”; $(link).up(“.fields”).hide(); }

function add_fields(link, association, content) { var new_id = new Date().getTime(); var regexp = new RegExp(“new_” + association, “g”) $(link).up().insert({ before: content.replace(regexp, new_id) }); }

// application_jquery.js function remove_fields(link) { $(link).prev(“input[type=hidden]“).val(“1”); $(link).closest(“.fields”).hide(); }

function add_fields(link, association, content) { var new_id = new Date().getTime(); var regexp = new RegExp(“new_” + association, “g”) $(link).parent().before(content.replace(regexp, new_id)); } [/javascript]

Back to Blog