0

If you need to render ERB markup that is stored in a database or a string, I discovered an easy way (though finding it was a little harder). I found a tip via a Robby On Rails blog post, which led me to the ticket he opened with a patch and a comment from the Rails team on a way to do this without patching Rails:


erb_template = grab_erb_from_database
content = render_to_string(:inline => erb_template)

Note: the render_to_string method is a protected controller method, so you will need to call this code in the action and store it in an instance variable for the view.

[tags]Ruby on Rails, ERb, rails rendering[/tags]

Leave a Reply