Sometimes you don’t need fancy flash message handling in your Rails application. Here’s a little helper method for those occasions:
def display_flash
flash.map do |level, message|
content_tag("p", message, :class => "flash-#{level}")
end
end
Say you do the following somewhere:
flash[:info] = "Your pizza has been ordered."
flash[:warn] = "Your pizza will unfortunately be cold."
The output of display_flash
will be:
<p class="flash-info">Your pizza has been ordered.</p>
<p class="flash-warn">Your pizza will unfortunately be cold.</p>
Simple and easy, like it should be.