views:

124

answers:

2

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?

A: 

can you re-write it like this?

module ApplicationHelper   
  def flash_helper 
    s = ""
    flash.each do |key, msg|
      s += content_tag :div, msg, :class => key
      ## "<div class=\"key\">" + msg + "</div>"
    end
    return s
  end
end
house9
+1  A: 

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
Voyta