Search code examples
javascriptruby-on-rails-3juggernaut

Rails 3: Passing a string from Ruby to Javascript?


The Jist:

In a <script type="text/javascript"> I want to access a static (won't ever change after Rails delivers page to client) string from Ruby to Javascript.

More Detail (AKA: Why I want to do it.)

I use a push server called Juggernaut and it has to connect to the appropriate "channel", determined by a variable in the controller. The Juggernaut syntax for "listening" to the Juggernaut server is:

j.subscribe("channel", function(data) { })

I want it to be:

j.subscribe(<%= @myChannel %>, function(data) { })

Solution

  • Most likely your @myChannel doesn't contain ".

    You should use:

    j.subscribe("<%= @myChannel %>", function(data) { })