views:

34

answers:

2

Hi, I have the following code.

   def add_resume_link(name, form)
     link_to_function name do |page|
       html = form.fields_for :resumes, @general_resume.resumes.build, :child_index => 'NEW_RECORD' do |form_parent|
               render :partial => 'resume_form', :locals=>{:form=>form_parent} 
            end
       page << "$('resumes').insert({ bottom: '#{escape_javascript(html)}'.replace(/NEW_RECORD/g, id) });"
      end
    end

And on the resume_form i have somewhere:

 =add_skill_link("Add Skill", form, "resume_#{id}_skills")

and the function looks like:

  def add_skill_link(name, form, id)
    link_to_function name do |page|
      html = form.fields_for :skill_items, @general_resume.skill_items.build, :child_index => 'NEW_RECORD' do |form_parent|
        render :partial=>'skill_form', :locals=>{:form=>form_parent, :parent=>id}
      end
      page << "$('#{id}').insert({ bottom: '#{escape_javascript(html)}'.replace(/NEW_RECORD/g, new Date().getTime()) });"
    end
  end

So basically i have a javascript code which dinamically adds a piece of html (add_resume) and contains another javascript code which dinamically adds a select box to the page. My problem is that the add_skill_link works fine if i use from the server side, i mean rendering from server side. And gets double escaped when using within the upper described way. I tried to remove the escape_javascript from the add_skill_link bit still not good. Any ideas?

A: 

Is this HAML?

=add_skill_link("Add Skill", form, "resume_#{id}_skills")

If so, you need to prevent HAML from escaping your output:

!=add_skill_link("Add Skill", form, "resume_#{id}_skills")
jdeseno
Thanks for your answer, finally I changed the whole thing, probably you're right, but i don't know if this solves my problem.
dombesz
A: 

I observed that things get too messy, finally I got my solution from Ryan Bates example application, he has a railscast about nested models, and there I browsed the branches and i got a branch with a nice clean solution to this problem. link text

dombesz