Rails3 ... JQuery .. strange behavior

I am doing an Ajax call, rendering 'done.js.erb' in which I wrote a jQuery append built from an helper current_snippet

$('#upload_tables').append("<%= current_snippet(@remote_locker, @current) -%>"); RAISES AN ERROR : missing ) after argument list

--- debugging the current_snippet helper, I get an html string as output

"<tr id='table_instructors'><td><img alt='Ajax-loader' height='16' src='/images/ajax-loader.gif' width='16' /></td><td>table_instructors</

<td><a href=\"/en/admin/remote_lockers/4d7b27b8a326cb033d00000b/

reloading.js?table=table_instructors\" data-remote=\"true\">start</a></

</tr>"

-- but strange ... if I copy this string into the js file (rather than calling the snippet helper) then NO ERROR ...

$('#upload_tables').append("<tr id='table_instructors'><td><img alt='Ajax-loader' height='16' src='/images/ajax-loader.gif' width='16' /></td><td>table_instructors</td><td><a href=\"/en/admin/ remote_lockers/4d7b27b8a326cb033d00000b/reloading.js? table=table_instructors\" data-remote=\"true\">start</a></td></tr>");

so the output string is well escaped ... why plain string is working well , but helper call is not ... I already used another snippet helper in a previous js line without such problem.... $('#<%= @previous -%>').replaceWith("<%= previous_snippet(@previous) - %>"); so it's not the js line writing....

if I insert a simple link tag in the helper, rather than generating it , ( html << "<a href='#'>Start</a>" ) then $('#upload_tables').append("<%= current_snippet(@remote_locker, @current) -%>"); doesn"t raise ANY ERROR

"<tr id='table_instructors'><td><img alt='Ajax-loader' height='16' src='/images/ajax-loader.gif' width='16' /></td><td>table_instructors</

<td><a href='#'>Start</a></td></tr>"

it seems the 'issue' is in the link_to generated in the helper link_to I18n.t(:start), reloading_admin_remote_locker_path(remote_locker, :table => current, :format => :js), :remote => true

any clue ? thanks

I am doing an Ajax call, rendering 'done.js.erb' in which I wrote a jQuery append built from an helper current_snippet

$('#upload_tables').append("<%= current_snippet(@remote_locker, @current) -%>"); RAISES AN ERROR : missing ) after argument list

You're not escaping the output of current snippet - if it contains any " then that will screw up stuff

If you inspect the output of current_snippet the it will print " characters as \" but that's just how it displays stuff - it doesn't mean that any escaping has actually taken place. There's an escape_javascript (or something similarly named) method in rails

Fred

[SOLVED] after playing with the snippet generation , I finally resolved to modify the way the link_to was generated by writing myself the link tag ....

    path = reloading_admin_remote_locker_path(remote_locker, :table => current, :format => :js)     html << '<a href=' + "#{path} data-remote='true'>#{I18n.t(:start)} </a></td></tr>"

I can even write it in one line... but I'll have a look at the escape_javascript as suggested.... thanks a lot