Take the 2-minute tour ×

How do I achieve this?

In a controller

@arr = ["<one>", "<two>"]

In a view (haml)

= @arr.join("<br>")

As you guess, "<br>" shouldn't be escaped. So the result would be like the following.


How do I do that?



share|improve this question

2 Answers 2

up vote 1 down vote accepted

You could roll your own:

''.html_safe.tap {|x|
  arr.each_with_index { |el, ix|
    x << el
    x << raw("<br/>") if ix < arr.size-1

Also look at the Array.join code in Rails

share|improve this answer
Wow. This is much more complex than I thought. Thanks. –  Sam Kong Mar 6 '11 at 6:33

Rails has this built in.

<%= safe_join(@arr, "<br />".html_safe) %>
share|improve this answer
might be obvious, but worth noting this only works in the view. –  drewish May 19 at 21:21

Your Answer


