title: Assigning a rails value to a global variable and use it in javascript
body: <p>I have a javascript function which takes rails value like</p>
  
  <pre><code>&lt;body onload="myFunction(&lt;%p%&gt;)"&gt;
  </code></pre>
  
  <p>and I'm trying to pass a value coming from the controller like this</p>
  
  <pre><code>&lt;% if logged_in? -%&gt;&lt;%p= current_user.id %&gt;&lt;% end -%&gt; but here the p doesn't contain the value. this works if I put code like this
  &lt;body onload="myFunction(&lt;%= current_user.id%&gt;)"&gt;
  &lt;% if logged_in? -%&gt;&lt;%= current_user.id %&gt;&lt;% end -%&gt;
  </code></pre>
  
  <p>But I need a further requirement, so another line like this should be add</p>
  
  <pre><code>&lt;% if logged_out? -%&gt;&lt;%p= current_user.id %&gt;&lt;% end -%&gt;
  </code></pre>
  
  <p>So if the user is logged out then the value p will passed to the javascript function. I know this is a small thing but don't know how to do it, I'm new to ror so please help and if you have tutorials to learn this point me too, so that can I save the time of both you and me in the future.</p>