Module: ErrorMessagesHelper
- Defined in:
- lib/generators/bootstrapped/layout/templates/error_messages_helper.rb
Defined Under Namespace
Modules: FormBuilderAdditions
Instance Method Summary collapse
- #display_flash_message ⇒ Object
-
#error_messages_for(*objects) ⇒ Object
Render error messages for the given objects.
Instance Method Details
#display_flash_message ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/generators/bootstrapped/layout/templates/error_messages_helper.rb', line 17 def partials = String.new flash.each do |key, value| css_class = key.to_s.eql?('notice') ? 'success' : 'error' partials << render( :partial => 'share/flash', :locals => { :css => css_class, :message => value }) end partials.html_safe end |
#error_messages_for(*objects) ⇒ Object
Render error messages for the given objects. The :message and :header_message options are allowed.
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/generators/bootstrapped/layout/templates/error_messages_helper.rb', line 3 def (*objects) = objects. [:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields") [:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.") = objects.compact.map { |o| o.errors. }.flatten unless .empty? # forced as error but may not abstractly always be the case content_tag(:div, :class => "alert-message block-message error") do list_items = .map { |msg| content_tag(:li, msg.html_safe) } content_tag(:h2, [:header_message].html_safe) + content_tag(:p, [:message].html_safe) + content_tag(:ul, list_items.join.html_safe) end end end |