rss

Feb
17

Rails flash messages helper

Posted (Amit) in Ruby on Rails on 17-02-2009

2

display_flash(:error) # to display a specific flash message
display_flash # to display all flash messages

1
2
3
4
5
6
7
8
9
10
11
12
13
# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  FLASH_TYPES = [:error, :warning, :success, :message]
  def display_flash(type = nil)
    html = ""
    if type.nil?
      FLASH_TYPES.each { |name| html << display_flash(name) }
    else
      return flash[type].blank? ? "" : "#{flash[type]}"
    end
    html
  end
end
Share

Comments (2)

Amit

Hey Nuks, i saw your creation, its nice. It would be very nice if you can write an article about how to create a plug-in and what are the different file for a plug-in and what they do.

Thanks,
Amit

Post a comment



Amit Yadav is Stephen Fry proof thanks to caching by WP Super Cache