So I have a have a solution for this, but I wanted to get some opinions and see if there was a better way to do this.
My problem is basically that I list of data that will get generated on load by RoR and then have JS controls to view subsets. I would rather not have to support two versions of what is basically the same HMTL. So my solution is this, I have a ruby partial that looks something like this:
<% value1 = jsmode ? '#{value1}' : object.value1
value2 = jsmode ? '#{value2}' : object.value2 $>
<div class="object_template">
<div><$= value1 $></div>
<div><%= value2 %></div>
</div>
So when I render the partial with ruby, I pass in a jsmode of false and it renders like a normal partial. Then I will render the partial again wrapped with a div with an ID of template but this time with a jsmode of true. This will render the html with the #{} strings. I can then pass the template to prototype Template object like this:
new Template($('template')).evaluate({value1: '111', value2: '222'});
So my question is, is there a better way to do this?
I know that I can use the #{} construct to pass variables to RoR if I wrap them with double quotes, but I need the #{} to render for the JS template.
Thoughts?