From: Eric Christopherson Date: 2011-02-16T08:29:43+09:00 Subject: Re: Assign Ruby string value to Javascrip variable? On Tue, Feb 15, 2011 at 5:05 AM, cz wrote: > Hi: > > Is it possible to assign a ruby string value to a javascript variable? > I can display the ruby value on the browser. It looks fine, but when I > try to pass the value to a javascript variable, an error ocurrs > (unterminated string literal). The code snippet below is my attempt. > > var str = '<%= #{@str} %>'; I'm guessing the problem is that you're using string interpolation syntax (#{...}), but outside of a double-quoted string. (Even if you were to use double quotes in your JavaScript here, it wouldn't could, because the erb expression is still not in Ruby quotes.) Just use: var str = '<%= @str %>'; > > I also tried the Ajax approach and that didn't work either. I am knew > to Ruby, Sinatra, and Haml. That being said, I am surprised at how > difficult this stuff is. Java and pHP were much easier. Any help or > hints would be greatly appreciated. Thanks in advance. > > cz > >