title: How to get rails controller variable in js file
body: <p>I have a variable in rails controller like</p>
  
  <pre><code>def index
  @approveflag = true
  end
  </code></pre>
  
  <p>I need to access this variable in my javascript code, I used the code given below
  in index.html.erb</p>
  
  <pre><code>&lt;script&gt;
  alert("&lt;%=@approveflag%&gt;")
  &lt;script&gt;
  </code></pre>
  
  <p>It works fine with result "true".But when I moved this code to its corresponding .js file it gives an alert with result string ""&lt;%=@approveflag%>"".
  What is the reason. How can I solve this?</p>
  
  <p>Thanks in advance.</p>