I have this class class ErrorFormBuilder, which allows me to add a description of the error next to the corresponding field in the form of a form:
class ErrorFormBuilder < ActionView::Helpers::FormBuilder
def label(method, text = nil, options = {})
text = text || method.to_s.humanize
object = @template.instance_variable_get("@#{@object_name}")
unless object.nil? || options[:hide_errors]
errors = object.errors.on(method.to_sym)
if errors
text += " <br/><span class=\"error\">#{errors.is_a?(Array) ? errors.first : errors}</span>"
end
end
text += " #{options[:additional_text]}" if options[:additional_text]
super(method, text, options)
end
end
But HTML:
text += " <br/><span class=\"error\">#{errors.is_a?(Array) ? errors.first : errors}</span>"
escaped by default in the view ... I tried adding the parameter {: escape => false}:
super(method, text, options.merge({:escape => false}))
without success
Is there any way around this behavior?
thank
source
share