How can I replace this with helper?
<% if flash[:error] %>
<% end %>
<% if flash[:warning] %>
<% end %>
<% if flash[:notice] %>
<% end %>
How can I replace this with helper?
<% if flash[:error] %>
add one def in application_helper.rb
like :
def show_flash(flash)
html = “”
if flash[:error]
html += “
then change in view.
from
<% if flash[:error] %>
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs