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 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.
yes you can, but where you are doing it, in the view.js.erb file?
···
On Tue, Feb 15, 2011 at 5:05 AM, cz <raymanojin@gmail.com> 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 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.
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 %>';
···
On Tue, Feb 15, 2011 at 5:05 AM, cz <raymanojin@gmail.com> wrote:
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.
<span class='progressBar' id='element<%= todo.id %>'
so the name id=elementWhatevercomefromdatabase
···
On Tue, Feb 15, 2011 at 5:09 AM, Lorenzo Brito Morales <lorenzo.brito@gmail.com> wrote:
yes you can, but where you are doing it, in the view.js.erb file?
On Tue, Feb 15, 2011 at 5:05 AM, cz <raymanojin@gmail.com> 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 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.
Not easily, assuming you're doing client-side JS. By the time the
browser is interpreting the JS, the Ruby is all done and gone (having
executed on the server, in order to create the page with the JS on
it). The closest you can do is to use the JS to create custom links,
AJAX requests, etc. that you can fire off, and thereby affect values
on the server.
-Dave
···
On Wed, Oct 12, 2011 at 06:17, Bala TS <bdeveloper01@yahoo.com> wrote:
Is it possible to Assign Java script value to Ruby value?
--
LOOKING FOR WORK, preferably Ruby on Rails, in NoVa/DC; see main web site.
Main Web Site: davearonson.com
Programming Blog: codosaur.us
Excellence Blog: dare2xl.com