Module: Bounga::FlashHelper::ViewHelpers
- Defined in:
- lib/flash_helper.rb
Overview
Global options for helpers
Options for flash helpers are optional and get their default values from the Bounga::FlashHelper::ViewHelpers.flash_options
hash. You can write to this hash to override default options on the global level:
Bounga::FlashHelper::ViewHelpers.[:notice_class] = 'my_notice'
By putting this into “config/initializers/flash_helper.rb” (or simply environment.rb in older versions of Rails) you can easily override any default option.
Constant Summary collapse
- @@flash_options =
default options that can be overridden on the global level
{ :list_class => 'errors_list', :notice_class => 'notice', :errors_class => 'errors', :warning_class => 'warning', :default_message => 'There are problems in your submission:' }
Instance Method Summary collapse
- #activerecord_error_list(errors) ⇒ Object
-
#display_flashes(message = @@flash_options[:default_message]) ⇒ Object
Display flash messages.
Instance Method Details
#activerecord_error_list(errors) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/flash_helper.rb', line 82 def activerecord_error_list(errors) error_list = '<ul class="' + @@flash_options[:list_class] + '">' error_list << errors.collect do |e, m| "<li>#{e.humanize unless e == "base"} #{m}</li>" end.to_s << '</ul>' error_list end |
#display_flashes(message = @@flash_options[:default_message]) ⇒ Object
Display flash messages. You can pass an optional string as a parameter. It will be display before error messages.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/flash_helper.rb', line 61 def display_flashes( = @@flash_options[:default_message]) if flash[:notice] flash_to_display, level = flash[:notice], @@flash_options[:notice_class] elsif flash[:warning] flash_to_display, level = flash[:warning], @@flash_options[:warning_class] elsif flash[:errors] level = @@flash_options[:errors_class] if flash[:errors].instance_of? ActiveRecord::Errors flash_to_display = .dup flash_to_display << activerecord_error_list(flash[:errors]) else flash_to_display = flash[:errors] end else return end flash.discard(:notice); flash.discard(:warning); flash.discard(:errors) content_tag 'div', flash_to_display, :class => "#{level}" end |