Module | Mack::ViewHelpers::ActiveRecordHelpers |
In: |
lib/mack-active_record/helpers/orm_helpers.rb
|
DEFAULT_PARTIAL | = | %{ <div class="errorExplanation" id="errorExplanation"> <h2><%= pluralize_word(errors.size, "error") %> occured.</h2> <ul> <% for error in errors %> <li><%= error %></li> <% end %> </ul> </div>}.strip unless Mack::ViewHelpers::ActiveRecordHelpers.const_defined?("DEFAULT_PARTIAL") |
# File lib/mack-active_record/helpers/orm_helpers.rb, line 20 20: def error_messages_for(object_names = [], view_partial = nil) 21: object_names = [object_names] 22: object_names.flatten! 23: app_errors = [] 24: object_names.each do |name| 25: object = instance_variable_get("@#{name}") 26: if object 27: object.errors.each do |key, value| 28: key = key.to_s 29: if value.is_a?(Array) 30: value.each do |v| 31: if v.match(/^\^/) 32: app_errors << v[1..v.length] 33: else 34: if key.class == String and key == "base" 35: app_errors << "#{v}" 36: else 37: app_errors << "#{object.business_display_name} #{key.underscore.split('_').join(' ')} #{v}" 38: end 39: end 40: end 41: else 42: if value.match(/^\^/) 43: app_errors << value[1..value.length] 44: else 45: if key.class == String and key == "base" 46: app_errors << "#{value}" 47: else 48: app_errors << "#{object.business_display_name} #{key.underscore.split('_').join(' ')} #{value}" 49: end 50: end 51: end 52: end 53: end 54: end 55: unless app_errors.empty? 56: app_errors.uniq! 57: if view_partial.nil? 58: if File.exist?(File.join(Mack.root, "app", "views", "application", "_error_messages.html.erb")) 59: render(:partial, "application/error_messages", :locals => {:errors => app_errors}) 60: else 61: render(:inline, DEFAULT_PARTIAL, :locals => {:errors => app_errors}) 62: end 63: else 64: render(:partial, view_partial, :locals => {:errors => app_errors}) 65: end 66: else 67: "" 68: end 69: end