I usually add such methods to my ApplicationHelper:
def flash_message(type, text)
flash[type] ||= []
flash[type] << text
end
And
def render_flash
rendered = []
flash.each do |type, messages|
messages.each do |m|
rendered << render(:partial => 'partials/flash', :locals => {:type => type, :message => m}) unless m.blank?
end
end
rendered.join('<br/>')
end
And after it is very easy to use them:
You can write something like:
flash_message :notice, 'text1'
flash_message :notice, 'text2'
flash_message :error, 'text3'
in your controller.
And just add this line to your layout:
<%= render_flash %>