RJS throwing 'rubycode' exception

All,

In an RJS template, how could I pass ruby variables values to the
javascript without getting the RJS Exception: rubycode? This is what I’m
doing (as an example) and is throwing the exception:

index.rjs

names = [“ruby”, “ajax”]
page << “alert(#{names})”

You think that wouldn’t work because its an array, right? Ok, so if I
convert the array to string:

index.rjs

names = [“ruby”, “ajax”]
page << “alert(#{names.to_s})”

still not working.

Also, it is possible to assign a JS variable’s value to a ruby variable?
Like this pseudo code:

index.rjs

page << “js_var = document.getElementById(‘my_var’).value”
ruby_var = js_var

Thanks a lot.

– Mark

names = [“ruby”, “ajax”]
page << “alert(#{names.to_s})”

I think this should do it:

names = [“ruby”, “ajax”]
page << “alert(’#{names.to_s}’)”

(note the extra quotes in there for the javascript string.)