I have the snippet below that runs without errors, however, it returns unicode characters in the response:
if params[:template] == 'Application Acknowledgement'
render json: { :template => render_to_string(:template => "template.erb") }
end
The ERB sends back the HTML template with the dynamic content, but the below HTML looks like this:
HTML in template:
<!doctype html>
<html>
<head>
</head>
</html>
HTML returned by the above snippet:
\u003c!doctypehtml\u003e\n\u003chtml\u003e\n\t\u003chead\u003e
How can I return normal UTF-8 HTML from the controller as a string in Rails?
Addition
The problem lies in converting unicode string to json e.g.:
"абв".to_json
becomes
"\"\\u0410\\u0411\\u0412\""
Whereas JSON::dump('АБВ')
returns "\"АБВ\""
, every single one of unicode characters passed to render json:
becomes escaped.
How to avoid escaping unicode symbols in rendering json?