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
<script type='text/javascript'> htmlVar = '<%= render :partial => "some/partial" %>'; </script>
Looks like rails..
There could be better ways to achieve what you are after.
and that is not HTML you are inserting.. that is part of rails code.. that needs to be on the view folder to work correctly as far as I know it..
if required use JS as the above post suggests and insert HTML
um, duh
sorry, that was rude.
yeah its rails code. and yes, i will be using innerHTML (i think this is what you mean by insert HTML, no?). but i need to get it into the js to do that. and i want to keep the view in the views folder rather than typing it into the js and mucking up my mvc seperation.