Rails ApplicationHelper Escaping HTML without a return statement

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 get nothing if not I return . When I call <%= flash_helper %> , the HTML is hiding in my view. What gives? How can I prevent HTML escaping?

+4
source share
2 answers

You can use the 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 
+4
source

can you rewrite 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 
0
source

Source: https://habr.com/ru/post/1307876/


All Articles