Reputation: 43
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?
Upvotes: 4
Views: 627
Reputation: 6225
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
Upvotes: 4
Reputation: 20624
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
Upvotes: 0