I’m using Rails 3. I want to display generated html fragment inside erb template
<%= "<div>Foo Bar</div>" %>
Rails encodes div tags.
If I’m correct in Rails 2 <%=h causes html escaping. Seems that it was changed in Rails 3. How can insert html fragment without encoding in Rails 3?
Regards,
Alexey.
I assume by encoding you mean the html-escaping:
To put out raw html in Rails 3 you can use three different approaches.
your can use the
rawhelper to output raw htmlmore information: ActionView::Helpers::OutputSafetyHelper#raw
You can mark the string as
html_safemore information: String#html_safe and ActiveSupport::SafeBuffer#new
You can sanitize your output with
sanitizemore information: ActionView::Helpers::SanitizeHelper#sanitze
Some more Information: