Galen King
Galen King

Reputation: 772

How do I convert an entire block in erb to html entities?

I have something like the following:

<%= content_tag(:table, class: "table") do %>
…
Rows and cells etc
…
<% end %>

I want to output it as raw HTML for users to copy-and-paste. How do I do that?

Can I wrap the entire block in something like <%= raw do %>…<% end %>? (That obviously doesn't work BTW)

Upvotes: 0

Views: 79

Answers (1)

piersadrian
piersadrian

Reputation: 1703

CGI::escapeHTML can do it. You should be able to call

<%= CGI.escapeHTML content_tag(:table, class: "table") do %>
  ...
<% end %>

Update, better way:

The h method, of course!

<%=h content_tag(:table, class: "table") do %>
  ...
<% end %>

Upvotes: 2

Related Questions