title: Sharing templates with Rails and Javascript
body: <p>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.</p>
  
  <p>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:</p>
  
  <pre><code>&lt;% value1 = jsmode ? '#{value1}' : object.value1
  value2 = jsmode ? '#{value2}' : object.value2 $&gt;
  &lt;div class="object_template"&gt;
  &lt;div&gt;&lt;$= value1 $&gt;&lt;/div&gt;
  &lt;div&gt;&lt;%= value2 %&gt;&lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>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:</p>
  
  <pre><code>new Template($('template')).evaluate({value1: '111', value2: '222'});
  </code></pre>
  
  <p>So my question is, is there a better way to do this?</p>
  
  <p>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.</p>
  
  <p>Thoughts?</p>