title: string interpolation for double-quoted attribute value in erb
body: <p>How can I write a double-quoted attribute-escaped erb expression and get the correct escaping behavior?</p>
  
  <p>For example, I'd like something that will output:</p>
  
  <pre><code>value="Hello World"
  </code></pre>
  
  <p>if <code>should_print_value</code> is true, and assuming <code>myvalue</code> = <code>Hello World</code></p>
  
  <p><strong>Edit</strong>: Note: <code>myvalue</code> may contain malicious content</p>
  
  <p><strong>Approach 1</strong></p>
  
  <p>If I try something like </p>
  
  <pre><code>&lt;%= "value=\"#{myvalue}\"" if should_print_value %&gt;
  </code></pre>
  
  <p>erb will escape the double quotes, resulting in <code>value=&amp;quotHello</code> and another attribute named <code>World&amp;quot=""</code></p>
  
  <p><strong>Approach 2</strong></p>
  
  <p>The simplest solution I've come up with is to do:</p>
  
  <pre><code>&lt;% if should_print_value %&gt;
    value="&lt;%= myvalue %&gt;"
  &lt;% end %&gt;
  </code></pre>
  
  <p>But I'm still curious as to if it's possible using the <code>&lt;%= "value=.... %&gt;</code> syntax of Approach 1.</p>