如何从javascript访问Ruby配置变量

如何从javascript访问Ruby配置变量,javascript,ruby,ruby-on-rails-3.2,Javascript,Ruby,Ruby On Rails 3.2,我在application.rb中添加了一个配置变量,例如 module Www class Application < Rails::Application ... config.myurl = "http://localhost:8443/play" end 在application.html.erb中,我添加了 def before_filter # This variable will be available in all controlle

我在application.rb中添加了一个配置变量,例如

module Www
    class Application < Rails::Application
      ...
      config.myurl = "http://localhost:8443/play"
end
在application.html.erb中,我添加了

def before_filter
  # This variable will be available in all controller actions and views
  @url_global = Www::Application.config.myurl
end
<script type="text/javascript">
  var url_global = "<%= @url_global %>"
</script>
但无法识别@url\u global。实际上,我已经尝试过在javascript中使用var的许多不同变体,但没有任何效果。

我看到您声明

var url_global = "<%= @url_global %>";

我说的对吗?

我确实在没有@的情况下尝试了这种方法,而且变量也无法识别。您可以在浏览器中使用view source打开呈现的页面吗?发送给我它呈现的代码将其更改为url_global而不使用@dod work。我刚刚意识到我的问题是,在应用程序_controller.rb中,我使用了两次前过滤器。因此,我有一个类ApplicationControllerfunction ClickedOnSomething(someid){ var fullUrl = @url_global + '?id='+someid+'.html'; ... }
var url_global = "<%= @url_global %>";
var fullUrl = url_global + '?id='+someid+'.html';