Add dynamic nested attributes without nested form gem

Hello people

In my rails 3.0.9 app I’m trying to add nested attributes
dynamically, but I don’t want to use “nested form gem”

So I found this example

but this code doesn’t work

module ProjectsHelper
def remove_link_unless_new_record(fields)
unless fields.object.new_record?
out = ‘’
out << fields.hidden_field(:_delete)
out << link_to_function(“remove”, “$
(this).up(‘.#{fields.object.class.name.underscore}’).hide(); $
(this).previous().value = ‘1’”)
out
end
end
end

I think that lines which starts with “out <<” make some conflicts,
because I’ve checked the html (firebug) and the simbols “<” and “>”
doesn’t appear

<a href=“#” onclick=“$(this).up(‘.task’).hide(); $
(this).previous().value = ‘1’; return false;”>remove</a>

Can you help me please?? Thanks

Ok, I’ve followed this cast

but I get an error when I try to add the link to “add fields” (remove
works as expected) this is the error

NoMethodError in Projects#new

Showing /home/angelo/nestattr/app/views/projects/_form.html.erb

where line #24 raised:

undefined method `klass' for nil:NilClass

Extracted source (around line #24):

21:     <%= render "task", :f => t %>
22:   <% end %>
23: <p>
24:    <%= link_to_add_fields "Add task", f, :task %>
25: </p>
26:   <div class="actions">
27:     <%= f.submit %>

Currently I’m using rails 3.0.9, so maybe something has changed since
then, please, tell me what’s wrong