You can use escape_javascript()
to accomplish that:
var data = {
'name': "<%== escape_javascript @product.name %>",
#...
};
Link:
http://api.rubyonrails.org/classes/ActionView/Helpers/JavaScriptHelper.html#method-i-escape_javascript
The alias of this method is j
:
var data = {
'name': "<%== j @product.name %>"
}