Since the result of your {#render} is HTML, and although you can use it once, it might make sense to store it in HTML and retrieve it using JavaScript. Imitating patterns, here is an example of what I mean:
<script id="my_render" type="text/template"> #{render "layouts/show_some_file", title: "some_file"} </script> <script type="text/javascript"> $(document).ready(function () { var render_content = $("#my_render").html(); $(".someclass").hover(function () { $(this).append(render_content); }); }); </script>
It looks like a template. You use the script tag, but you set its type to something that does not cause its execution. Since script tags never appear on the page, you will never have problems with the image ... unlike inside the div ... the HTML is then "separated" from the rest of the page.
I'm sure there is a better solution using Ruby, but if you expose a partial view of JavaScript code, I need to ask why. It makes more sense to me to put a "template". I understand that this does not directly answer your immediate question, but this is an alternative :)
source share