Method: SimpleModel::ErrorHelpers#errors_for_flash

Defined in:
lib/simple_model/error_helpers.rb

#errors_for_flash(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/simple_model/error_helpers.rb', line 11

def errors_for_flash(options={})
  #set defaults and overwrite
  options = {:failed_action => "saving",
             :id => 'errorExplanation',
             :classes =>  ''}.merge!(options)

  error_list  = ""

  # The active_model errors object is not a normal hash and the each method
  # for the active_mode errors object does not perform as expected
  # so make it a plain hash
  {}.merge!(self.errors).each do |error,message|
    error_list << create_error_list(error,message)
  end
  error_string = "<div id='#{options[:id]}' class='#{options[:classes]}'><h2>#{self.errors_count}"
  error_string << " #{puralize_errors_string(self.errors)}"
  error_string << " prevented #{options[:failed_action]}.</h2><ul>"
  error_string << error_list
  error_string << "</ul></div>"
  error_string
end