title: How to access Ruby configuration variables from javascript
body: <p>I added a configuration variable in application.rb such as</p>
  
  <pre><code>module Www
      class Application &lt; Rails::Application
        ...
        config.myurl = "http://localhost:8443/play"
  end
  </code></pre>
  
  <p>After something is clicked on my page I would like to use the value of this config var in order to come up with my full url such as mypage.js having</p>
  
  <pre><code>function ClickedOnSomething(someid){
      var fullUrl = &lt;value of config.myurl&gt; + '?id='+someid+'.html'; 
      ...
  }
  </code></pre>
  
  <p>so that if for example the id of what I clicked on was 1776 then the fullUrl would be the string 
  <code>http://localhost:8443/play?id=1776.html</code></p>
  
  <p>I am using Ruby on Rails 3.2.3 and Ruby 1.9.3</p>
  
  <p>One thing I tried was going through the controller like the following:</p>
  
  <p>In application_controller.rb I added</p>
  
  <pre><code>def before_filter
    # This variable will be available in all controller actions and views
    @url_global = Www::Application.config.myurl
  end
  </code></pre>
  
  <p>In application.html.erb I added</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
    var url_global = "&lt;%= @url_global %&gt;"
  &lt;/script&gt;
  </code></pre>
  
  <p>Then in mypage.js I did</p>
  
  <pre><code>function ClickedOnSomething(someid){
      var fullUrl = @url_global + '?id='+someid+'.html'; 
      ...
  }
  </code></pre>
  
  <p>but @url_global is not recognized. I have actually tried many different variations of using the var in javascript but nothing is working for me.</p>