Helper

How can I replace this with helper?

<% if flash[:error] %>

<%= flash[:error] %>

<% end %>
<% if flash[:warning] %>
<%= flash[:warning] %>

<% end %>
<% if flash[:notice] %>
<%= flash[:notice] %>

<% end %>

add one def in application_helper.rb
like :

def show_flash(flash)
html = “”
if flash[:error]
html += “

#{flash[:error]}

end
if flash[:warning]
html + = “
#{flash[:warning]}

end
if flash[:notice]
html += “
#{flash[:notice]}

end
end

then change in view.
from
<% if flash[:error] %>

<%= flash[:error] %>
<% end %> <% if flash[:warning] %>
<%= flash[:warning] %>
<% end %> <% if flash[:notice] %>
<%= flash[:notice] %>
<% end %>

To
<%= show_flash(flash) %>

I hope it will help u…

Thank you

On Mon, Mar 23, 2009 at 7:31 PM, Fresh M.
<[email protected]

wrote:

<%= flash[:notice] %>
<% end %> -- Posted via http://www.ruby-forum.com/.


Wu You Duan

Or something like this:

def flash_messages
messages = []
%w(notice warning error).each do |msg|
messages << content_tag(:div, html_escape(flash
[msg.to_sym]), :id => “flash-#{msg}”) unless flash[msg.to_sym].blank?
end
messages
end

<%= flash_messages %>

Another similar method…

def show_flash
[:notice, :warning, :message].collect do |key|
content_tag(:div, flash[key], :class => “flash_#{key}”) unless
flash[key].blank?
end.join
end