Use escape_javascript instead of gsub as it is more idiomatic.