ruby-on-railshtml-escape

Rails: array.join with html in separator is escaped


I have an array of Strings containing unsave content (user input).

I want to join these Strings in my template, separated by <br />.

I tried:

somearray.join("<br />")

But this will also escape the sparator.

Is there a workaround, keeping in mind that the content of the array absolutely must be escaped?


Solution

  • Is there a reason it has to be a <br /> tag? Could you use a list instead?

    <ul>
      <% somearray.each do |item| %>
        <%= content_tag :li, item %>
      <% end %>
    </ul>