module ActionView
class Base
@@field_error_proc = Proc.new{ |html_tag, instance| "#{html_tag}" }
cattr_accessor :field_error_proc
end
end
module ApplicationHelper
def error_messages_for(object_name, options = {})
options = options.symbolize_keys
object = instance_variable_get("@#{object_name}")
if object && !object.errors.empty?
content_tag("div",
content_tag("p", "Se han producido errores guardando el formulario:") +
content_tag("ul", object.errors.full_messages.collect { |msg| content_tag("li", msg) }),
"id" => options[:id] || "errorExplanation", "class" => options[:class] || "alert message"
)
else
""
end
end
end
module ActiveRecord
class Errors
def full_messages
full_messages = []
@errors.each_key do |attr|
@errors[attr].each do |msg|
next if msg.nil?
full_messages << msg
end
end
return full_messages
end
end
end