1

I have the line below in a method that is an endpoint in my Rails API:

render json: { :template => render_to_string(:template => "emails/cases/approved.html.erb").html_safe }

The user sends a request to the server (POST) with some data, dependent on the data the user POSTs the server sends back an HTML "template"

It is an ERB template already rendered, and that's all working fine. However, when Rails sends back the HTML as a string with the populated variables in the ERB template, the string looks like this:

HTML:

<!doctype html>

And Rails response:

\u003c!doctype html\u003e\n\u003chtml

How can I prevent Rails from converting it to unicode characters?

1 Answer 1

1
render json: {template: raw(render_to_string(template: "emails/cases/approved.html.erb"))}
Sign up to request clarification or add additional context in comments.

2 Comments

I'm getting an error now, undefined method raw for #<CasesController>
my bad.. raw is only defined in the view. Use render_to_body instead of render_to_string which renders raw

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.