2

I have stored the content of a .html.erb file in the database. I now want to render the ERB data into a string without displaying it. I tried

rendered = render_to_string(:template => MailTemplate.find(1).body)

but it throws Missing template. Does the render_to_string method only work with an actual file?

1 Answer 1

4

You need to tell render to use a text string, not a template.

rendered = render_to_string(:text => MailTemplate.find(1).body)

http://api.rubyonrails.org/classes/ActionView/Helpers/RenderingHelper.html#method-i-render

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.