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

c# - Reactive Extensions ControlScheduler -

scala - Play Framework - how to bind form to a session field -

javascript - Enable/Disable form elements and changing the values of button at a time? -