Module Mack::ViewHelpers::ActiveRecordHelpers
In: lib/mack-active_record/helpers/orm_helpers.rb

Methods

Constants

DEFAULT_PARTIAL = %{ <div> <div class="errorExplanation" id="errorExplanation"> <h2><%= pluralize_word(errors.size, "error") %> occured.</h2> <ul> <% for error in errors %> <li><%= error %></li> <% end %> </ul> </div> </div> }

Public Instance methods

[Source]

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

[Validate]