Rails particles get double escaping when using link_to_function

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 resume_form

I have somewhere:

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

      

and the function looks like this:

  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 javascript code that dynamically adds the html ( add_resume

) part and contains other javascript code that dynamically adds a select box to the page.

My problem is that it add_skill_link

works great if I use server side, I mean server side rendering. And gets double escaped when used in the order above.

I tried to remove escape_javascript

from bits add_skill_link

still not very good.

Any ideas?

+2


a source to share


2 answers


I noticed things were getting too messy, finally I got my solution from Ryan Bates example, it has railscast about nested models and there I looked through the branches and I have a branch with a nice clean solution to this problem. link text



0


a source


Is this HAML?

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

      



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

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

      

+1


a source







All Articles