aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers/application_helper.rb
diff options
context:
space:
mode:
authorfrancis <francis>2007-08-23 17:39:42 +0000
committerfrancis <francis>2007-08-23 17:39:42 +0000
commit0e12859ba39820b7b5a755be998040d39cc70f6f (patch)
treec8436385764144e472d1072af55be349a700344d /app/helpers/application_helper.rb
parenta1e4c20771831d0a2bfe0fd6ee098818dd2b7d47 (diff)
Fix text of error messages.
Diffstat (limited to 'app/helpers/application_helper.rb')
-rw-r--r--app/helpers/application_helper.rb27
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