Only one solution you should use method ‘tag’ directly
Thank you, This works!
But finally I ended making a
getElementById(“name”).onfocus = …
on load instead of changing all my text_field_tag with tag
P.S: Do not use inline JS .
You’re right, but my problem is that I have ruby code in rhtml that
generates css and javascript codes. These codes are not static but
depend on ruby variables values.
I can’t figure out how to pass a ruby variable into an external css or
js file…
So I have to keep all the code in one big (sigh!) rhtml…
Max S. wrote in post #1084457:
I can’t figure out how to pass a ruby variable into an external css or
js file…
So I have to keep all the code in one big (sigh!) rhtml…
The simplest way is to not pass the data to JavaScript, but rather get
the value from the DOM using JavaScript/jQuery. This is accomplished by
using HTML5 data attributes.
Say you have a Ruby variable x:
HTML
My content
JavaScript
function myFunction() {
var x = $(‘#my_div’).data(“x”);
// Do something with x
}
Ryan B. did a Railscasts episode on a few techniques to keep your
JavaScript unobtrusive and yet still have access to your Ruby data:
Max S. wrote in post #1084457:
I can’t figure out how to pass a ruby variable into an external css or
js file…
So I have to keep all the code in one big (sigh!) rhtml…
The simplest way is to not pass the data to JavaScript, but rather get
the value from the DOM using JavaScript/jQuery. This is accomplished by
using HTML5 data attributes.
Say you have a Ruby variable x:
HTML
My content
JavaScript
function myFunction() {
var x = $(‘#my_div’).data(“x”);
// Do something with x
}
Ryan B. did a Railscasts episode on a few techniques to keep your
JavaScript unobtrusive and yet still have access to your Ruby data: