I have a variable in my controller @data that is a very long string. I have a javascript function that needs access to this variable. Should I do this:
$(document).ready(function(){
var data='<%=j @data%>'
})
or should I put the string in an html data-attribute and then do something like:
<div data-stuff="<%=h @data%>"></div>
$(document).ready(function(){
var data=$("div").data('stuff')
})
If one is preferable, why?