Since you are not using a more common templating framework which automates escaping values, you need to manually ensure that ALL user-provided values you emit into your HTML are properly escaped.
You can use the CGI
module for that which ships with Ruby:
require 'cgi'
def h(value)
CGI.escapeHTML(value)
end
json = RubyArrayOfHashes.to_json
html = "<div data-track=\"#{h json}\">something</div>
Note that depending on how the emitted data is interpreted, you might need to use other escaping methods. If you are e.g. emitting Javascript code between <script>
tags, you need to escape it differently.
In general, you should investigate ways to automate the escaping of values similar to what Rails does in recent versions. Having to manually escape all emitted values can quickly lead to bugs when you forgot to escape some data, leading to security issues such as XSS vulnerabilities.