Module: WcmsComponents::AlertsHelper
- Defined in:
- app/helpers/wcms_components/alerts_helper.rb
Instance Method Summary collapse
- #alert_class(type) ⇒ Object
- #alert_icon(type) ⇒ Object
- #all_alerts ⇒ Object
- #flash_alerts ⇒ Object
- #model_alerts(model = nil) ⇒ Object
Instance Method Details
#alert_class(type) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'app/helpers/wcms_components/alerts_helper.rb', line 30 def alert_class(type) case type.to_s.to_sym when :error, :alert 'alert-danger' when :warn, :warning 'alert-warning' # default yellow else 'alert-info' end end |
#alert_icon(type) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/wcms_components/alerts_helper.rb', line 19 def alert_icon(type) case type.to_s.to_sym when :error, :alert 'fa fa-exclamation-circle' when :warn, :warning 'fa fa-warning' else 'fa fa-info-circle' end end |
#all_alerts ⇒ Object
3 4 5 |
# File 'app/helpers/wcms_components/alerts_helper.rb', line 3 def all_alerts flash_alerts + model_alerts end |
#flash_alerts ⇒ Object
7 8 9 |
# File 'app/helpers/wcms_components/alerts_helper.rb', line 7 def flash_alerts flash.map { |key,val| {type: key, message: val} } end |
#model_alerts(model = nil) ⇒ Object
11 12 13 14 15 16 17 |
# File 'app/helpers/wcms_components/alerts_helper.rb', line 11 def model_alerts(model = nil) model ||= instance_variable_get("@#{controller_name.singularize}") return [] if model.nil? model.errors..map { |msg| {type: :error, message: msg} } end |