4

当我写

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

return除非我声明,否则我什么也得不到。当我调用<%= flash_helper %>. 是什么赋予了?如何防止 HTML 被转义?

4

2 回答 2

4

您可以使用concat方法(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
于 2010-04-25T18:44:29.607 回答
0

你能像这样重写它吗?

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
于 2010-04-24T16:53:45.063 回答