Strange javascript rendering

I have a form helper that looks like this:

#_alert.html.haml
= add_field_link “Add Email”, f, :notification_emails

#application_helper.rb
def add_field_link(name, f, association)
new_object =
f.object.class.reflect_on_association(association).klass.new
fields = f.fields_for(association, new_object, :child_index =>
“new_#{association}”) do |builder|
render(“home/” + association.to_s.singularize + “_fields”, :f =>
builder)
end
link_to_function(name,
h(“add_fields(this,’#{association}’,’#{escape_javascript(fields)}’)”))
end

:javascript
function add_fields(link, association, content) {
var new_id = new Date().getTime();
var regexp = new RegExp(‘new_’ + association, ‘g’);
$(link).prev(‘ul’).append(’

  • ’ + content.replace(regexp, new_id)
    • ’);
      }
  • This line here I had to use ’ rather than "/ because otherwise
    firebug will raise error “unexpected token &”:

    link_to_function(name,
    h(“add_fields(this,’#{association}’,’#{escape_javascript(fields)}’)”))

    but when I click on link its supposed to add a new field with model
    attributes but doesnt. I look in firebug console and see this:

    Add Email

    Any idea why it looks like this and why the expected behavior doesnt
    occur?

    thanks for response

    This was a simple fix. You dont escape html in rails 3.