jquery - escape javascript doesn't work with link_to_function (rails) -


this line works fine

        <%=link_to_function "name", "$('#thing_name').html('<p>name<p>')" %> 

this line doesn't

        <%=link_to_function "name", "$('#thing_name').html('<%= escape_javascript(thing.name) %>')" %> 

then rid of content within <%= %>

       <%=link_to_function "name", "$('#thing_name').html('<%= %>')" %> 

it still keeps complaining weird compile errors.

thanks in advance.

you inside erb block due opening <%= @ beginning, , cannot use one. use string interpolation evaluate ruby code inside string:

<%= link_to_function "name", "$('#thing_name').html('#{escape_javascript(thing.name)}')" %> 

alternatively, if reason don't want use interpolation:

<%= link_to_function "name", "$('#thing_name').html('" + escape_javascript(thing.name) + "')" %> 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -