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

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -