保存表单和字段验证失败时,我不希望完全修改标签.我不介意用div和一个"field_with_errors"类包装输入,但是如何阻止它包装标签呢?
我无法在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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1377 次 |
| 最近记录: |