Rails partial gets double escaped when using link_to_function
Posted
by dombesz
on Stack Overflow
See other posts from Stack Overflow
or by dombesz
Published on 2010-04-22T10:35:24Z
Indexed on
2010/04/22
10:43 UTC
Read the original article
Hit count: 228
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?
© Stack Overflow or respective owner