title: How to create a global js variable initialized by my Rails app variable the right way?
body: <p>In my AppController I have a variable @current_user. I want to create a global namespaced variable in accross my all js files so
  that it gets initialized when @current_user exists -- a user is loged in, that is. Also I want it to be namespaced so it won't rewrite or get rewritten by other js variables if there happen to be any with the same name.</p>
  
  <p>How can I properly do that?</p>
  
  <p>I think I should create a js variable in my base <strong>layout</strong>, at the very top:</p>
  
  <pre><code>&lt;script&gt;
  var currentUser = {};
  &lt;% if @current_user %&gt;
    currentUser = {id: &lt;%= @current_user.id %&gt;, email: '&lt;%= @current_user.email %&gt;'};
  &lt;% end %&gt;
  &lt;/script&gt;
  </code></pre>
  
  <p>Is this a solid approach? Or is there a better one?</p>
  
  <p>Also - how do I add a namespace to my js variable so that it'll become:</p>
  
  <pre><code> MyApp.currentUser
  </code></pre>
  
  <p>?</p>