diff options
Diffstat (limited to 'app/helpers')
-rw-r--r-- | app/helpers/application_helper.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 07bc01d6d..cf0845970 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7,4 +7,31 @@ module ApplicationHelper return stylesheet_link_tag( _n ).gsub( ' />', '>' ) end + # Copied from error_messages_for in active_record_helper.rb + def foi_error_messages_for(*params) + options = params.last.is_a?(Hash) ? params.pop.symbolize_keys : {} + objects = params.collect {|object_name| instance_variable_get("@#{object_name}") }.compact + count = objects.inject(0) {|sum, object| sum + object.errors.count } + unless count.zero? + html = {} + [:id, :class].each do |key| + if options.include?(key) + value = options[key] + html[key] = value unless value.blank? + else + html[key] = 'errorExplanation' + end + end + error_messages = objects.map {|object| object.errors.full_messages.map {|msg| content_tag(:li, msg) } } + content_tag(:div, + content_tag(:p, 'Please correct the following and try again.') << + content_tag(:ul, error_messages), + html + ) + else + '' + end + end + + end |