Rails ApplicationHelper Escaping HTML without return statement

actionview, escaping, helper, html, ruby-on-rails

Solution

You can use `concat` method (Rails >= 2.2.1)

module ApplicationHelper   
  def flash_helper 
    flash.each do |key, msg|
      concat(content_tag :div, msg, :class => key)
    end
    nil
  end
end

Problem

When I write ``` module ApplicationHelper def flash_helper flash.each do |key, msg| content_tag :div, msg, :class => key ## "<div class=\"key\">" + msg + "</div>" end end end ``` I do not get anything unless I `return` the statement. The HTML is escaped in my view when I call `<%= flash_helper %>`. What gives? How can I prevent the HTML from being escaped?

Original source