jquery - Passing a Rails Ruby Variable to Javascript -
There is a variable in my controller @ data which is a very long string I have a JavaScript function that accesses this variable is required. I should do this:
$ (document) .ready (function () {var data = '& lt;% = j = data% & gt;'})
< / Pre>or I should put the string in the html data-attribute and then something like this should be done:
If one is better, why?
Between two of your choices, preference is made.
But consider using gon gem:
Comments
Post a Comment