Module: Ramaze::Helper::Message
- Defined in:
- lib/zen/helper/message.rb
Overview
The Mesage helper is a Ruby implementation of the Codeigniter library "Message" (located here: https://github.com/isset/codeigniter-message). This helper was taken from another project of mine which can be found here: https://github.com/yorickpeterse/stumpert/
Usage
Basic usage is as following:
(:error, "Bummer, something went wrong!")
In your layout you'd do the following:
This will create and return the HTML for all the messages.
Instance Method Summary (collapse)
-
- (Object) display_messages(types = [:info, :error, :success])
Renders all the messages for the specified types.
-
- (Object) message(type, message)
Adds a new message to the list for the given type.
Instance Method Details
- (Object) display_messages(types = [:info, :error, :success])
Renders all the messages for the specified types.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/zen/helper/message.rb', line 51 def (types = [:info, :error, :success]) gestalt = ::Ramaze::Gestalt.new return if flash[:messages].nil? gestalt.div(:id => 'message_container', :class => 'container') do # Render each individual group types.each do |type| if type.respond_to?(:to_sym) type = type.to_sym end if flash[:messages].key?(type) gestalt.div(:class => "message #{type}") do # Render all the messages flash[:messages][type].each_with_index do |, index| flash[:messages][type].delete_at(index) gestalt.p { } end end end end end return gestalt.to_s end |
- (Object) message(type, message)
Adds a new message to the list for the given type.
35 36 37 38 39 40 41 42 43 |
# File 'lib/zen/helper/message.rb', line 35 def (type, ) if type.respond_to?(:to_sym) type = type.to_sym end flash[:messages] ||= {} flash[:messages][type] ||= [] flash[:messages][type].push() end |