Re: Multiple child models in a dynamic form

Has anyone converted this tutorial to jQuery?

I don't know the equivalent of:

$(this).previous().value = '1'

Re: Multiple child models in a dynamic form

You should check out the railscasts - http://railscasts.com/episodes/196-nest … orm-part-1

What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)

Re: Multiple child models in a dynamic form

The jQuery needed in the application.js (or wherever) for Rails 3.x is

function remove_fields(link) {
  $(link).prev("input[type=hidden]").val("1");
  $(link).parent(".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));
}
What you want and what you need are too often not the same thing!
When your head is hurting from trying to solve a problem, stop standing on it. When you are the right way up you will see the problem differently and you just might find the solution.
(Quote by me 15th July 2009)