Rich Collins successfully answered ParagramStudios's question:

I want to have my Javascript inject some HTML on the fly but I hate to put HTML in my js because it belongs in the view, not the public folder. I thought I could be slick and do something like this in a view to get the HTLM stored in a js variable:

<script type='text/javascript'>
htmlVar = '<%= render :partial => "some/partial" %>';
</script>

Unfortunately this gets screwed up by the line-returns in the partial. Is there a way to make this work or achieve a similar result using RJS or the Minus-R plugin?

People succeed in answering ParagramStudios's questions 26% of the time (9 successes in 34 attempts).

Answers by: darksanity | Rich Collins | vlambert

Rich Collins's Answer:

Reply by Rich Collins 480 days ago

You almost had it:

$('someElement').innerHTML = <%= render(:partial => 'some/partial').to_json %>

Reply by ParagramStudios 476 days ago

closer, but no cigar. that put the rhtml all on line which is part of the problem.

but i still need to make all the double quotes in the partial turn into single quotes. i'll try some regex, but if you know off the top of your head feel free to let me know.

Reply by ParagramStudios 476 days ago

oh nevermind, i didn't realize i nolonger needed the single quotes around the render. you rock!

Reply by Rich Collins 476 days ago

No problem - than ks for the reward :)