Please read for an updated status on RailsCasts:
Learn more or hide this
GitHub User: jwhiting
Actually, furthermore you really should be adding a to_s on @foo:
var foo = '<%= j @foo.to_s.html_safe %>';
Because if there's any chance @foo might not be a string, you'll get a NoMethodError trying to call html_safe on it.
I'm gonna go out on a limb here and wager that most Rails devs are not applying these three (count 'em, three) conversions on their values in order to splat them into a script?
var foo = '<%= j @foo.html_safe %>';
var foo = '<foo>';
Which is almost certainly not what you want.