I'm trying to pass a variable to a javascript function from a helper
function but I'm not getting it to work.  I think the problem is with
 #{domElement}

any ideas?
thanks!



This is how the helper function is called from the view:

<%= link_to_add_fields t('form.treatment.add'),
form, :treatments, :table %>


Then this is the helper function:

  def link_to_add_fields(name, f, association, domElement)
    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(association.to_s.singularize + "_fields", :f => builder)
    end
    link_to_function(name, h("add_fields(this, \"#{association}\",
\"#{escape_javascript(fields)}\", #{domElement})"))
  end


And this is the javascript function:

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

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to