Guest User

Untitled

a guest
Apr 27th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1.  
  2. module ActionView
  3. module Helpers
  4. module ActiveRecordHelper
  5. def error_messages_for(*params)
  6. better_msgs = {
  7. "Content type is not included in the list" => "That file type is not supported.",
  8. "Size is not included in the list" => "You must select a file smaller than 6MB in size."
  9. }
  10. options = params.extract_options!.symbolize_keys
  11. objects = params.collect {|name| instance_variable_get("@#{name}") }
  12. error_messages = objects.map {|o| o.errors.full_messages}
  13. unless error_messages.flatten!.empty?
  14. if options[:partial]
  15. render :partial => options[:partial],
  16. :locals => {:errors => error_messages}
  17. else
  18. header = "The following errors prevented this submission from being made:"
  19. error_list = error_messages.map {|m| content_tag(:li, better_msgs[m] || m)}
  20. contents = ''
  21. contents << content_tag(:h2, header)
  22. contents << content_tag(:ul, error_list)
  23. content_tag(:div, contents,
  24. :class => 'errorExplanation',
  25. :id => 'errorExplanation')
  26. end
  27. else
  28. ''
  29. end
  30. rescue
  31. ''
  32. end
  33. end
  34. end
  35. end
Add Comment
Please, Sign In to add comment