title: How to pass a instance html_safe string variable to js.erb
body: <p>It seems a stupid question, but there are no way to achieve this</p>
  
  <p>With Rails 4.2.5.</p>
  
  <p>in a remote call to the controller, </p>
  
  <pre><code>def update
    # ... save ...
    @notice="S'han trovat errors"
    # automatically renders update.js.erb
  end
  </code></pre>
  
  <p>in update.js.erb</p>
  
  <pre><code>alert('&lt;%=(@notice)%&gt;');
  </code></pre>
  
  <p>this is the output:
  <a href="https://i.stack.imgur.com/PulSI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PulSI.png" alt="enter image description here"></a></p>
  
  <p>What I've tried:</p>
  
  <p>1)In the controller: </p>
  
  <pre><code> @notice="S'han trovat errors".html_safe
  </code></pre>
  
  <p>2)another proof, in js.erb:  </p>
  
  <pre><code>  alert('&lt;%=raw(@notice)%&gt;');
  </code></pre>
  
  <p>In both cases, when javascript function <code>alert()</code> is  executed, it hangs without any message in terminal neither in browser console ¿?</p>
  
  <p>3)I have tried too:</p>
  
  <pre><code>alert('&lt;%=escape_javascript(@notice)%&gt;');
  </code></pre>
  
  <p>But doesn't work, shows "S'han trobat..."</p>
  
  <p><em>Of course, if I show in <code>index.html.erb</code>, <strong>@notice</strong> , the result is correct (S'han trobat..)</em></p>
  
  <p>I don't know how to pass from controller to js.erb a " ' " character in a string instance variable to be shown</p>
  
  <p>Thanks</p>