I used the following in a liquid filter to get at the flash;
module Liquid
module CommonFilters
# include other helper modules
include ApplicationHelper
# flash message notifications
def notifications(html_id)
if @context.registers[:controller].session && @context.registers
[:controller].session['flash']
html = ""
[:failure, :notice, :success].each do |key|
message = @context.registers[:controller].session['flash']
[key]
html += "<p class=\"#{key}\">#{message}</p>\n" unless
message.blank?
end
return "<div id=\"#{html_id}\">#{html}</div>" unless
html.blank?
end
end
end
end
Works for me; and then in the views use something like;
{{ 'flash' | notifications }}
to give something like;
<div id="myid">
<p class="failure">my failure</p>
<p class="notice">some notice message</p>
</div>
etc.
Of course this will only show the flash keys
matching; :failure, :notice, :success
m
Ps.. heres a test;
it "should show session flash messages" do
@context = Liquid::Context.new
@context.registers[:controller] = ApplicationController.new
@context.registers[:controller].session = Hash.new
notifications('myid').should be_nil
@context.registers[:controller].session['flash'] = {:notice =>
'some notice message'}
notifications('myid').should eql("<div id=\"myid\"><p class=
\"notice\">some notice message</p>\n</div>")
@context.registers[:controller].session['flash'] = {:notice =>
'some notice message', :failure => 'my failure', :unknown => 'blah'}
notifications('myid').should eql("<div id=\"myid\"><p class=
\"failure\">my failure</p>\n<p class=\"notice\">some notice message</p>
\n</div>")
end