Module: E9Rails::Helpers::ResourceErrorMessages::HelperMethods

Defined in:
lib/e9_rails/helpers/resource_error_messages.rb

Instance Method Summary collapse

Instance Method Details

#resource_error_messages!(options = {}) ⇒ Object

Assumes the definition of resource. Also accepts it as an option passed to the method.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/e9_rails/helpers/resource_error_messages.rb', line 19

def resource_error_messages!(options = {})
  object = options[:resource] || resource

  if object.errors.empty? || ( (errors_on = options.delete(:on)) && (errors_on & object.errors.keys).empty? )
    return ''
  end

  errors = object.errors.map {|attribute, msg| msg }.flatten.map {|m| "<li>#{m}</li>"}.join("\n")

  <<-HTML.html_safe
    <div id="errorExplanation">
      <ul>#{errors}</ul>
    </div>
  HTML
rescue => e
  ''
end