Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module ActionView
- module Helpers
- module ActiveRecordHelper
- def error_messages_for(*params)
- better_msgs = {
- "Content type is not included in the list" => "That file type is not supported.",
- "Size is not included in the list" => "You must select a file smaller than 6MB in size."
- }
- options = params.extract_options!.symbolize_keys
- objects = params.collect {|name| instance_variable_get("@#{name}") }
- error_messages = objects.map {|o| o.errors.full_messages}
- unless error_messages.flatten!.empty?
- if options[:partial]
- render :partial => options[:partial],
- :locals => {:errors => error_messages}
- else
- header = "The following errors prevented this submission from being made:"
- error_list = error_messages.map {|m| content_tag(:li, better_msgs[m] || m)}
- contents = ''
- contents << content_tag(:h2, header)
- contents << content_tag(:ul, error_list)
- content_tag(:div, contents,
- :class => 'errorExplanation',
- :id => 'errorExplanation')
- end
- else
- ''
- end
- rescue
- ''
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment