2012-09-05 15 views

回答

5

我无法在ActionView :: Base文档中找到关于field_error_proc方法的任何内容,但这里是我想出的解决方案。希望这会帮助其他人!

ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| 
    unless html_tag =~ /^<label/ 
    "<div class=\"field_with_errors\">#{html_tag}</div>".html_safe 
    else 
    html_tag.html_safe 
    end 
end 
+0

只需添加,将其放置在要使用的config/initializers中的文件中。 – riley

+0

它为我工作!谢谢。 –

-1

而不必例如

<%=label "name", :name%> 

,删除:name并有

<%=label "name"%> 

这将停止包装的。

+0

这消除了与其相关的'

相关问题