ruby-on-rails – 如何更改默认rails error div“field_with_errors”

我正在使用 sorcery认证和 twitter bootstrap.

我想通过更改默认的轨道< div class =“field_with_errors”>通过twitter的引导方式在我的注册表单上设置错误消息.它被添加到DOM中.

做这样的事情的铁路公约是什么?

我想你可以添加一些操纵DOM的javascript来重命名< div class =“field_with_errors”>,但这似乎是一个黑客.似乎应该有一种方法来重写这个在rails,但我不知道该怎么做.

这是引导需要您标记错误以使用其内置的表单错误样式:

<div class="control-group error">
  <label class="control-label" for="inputError">Input with error</label>
  <div class="controls">
    <input type="text" id="inputError">
    <span class="help-inline">Please correct the error</span>
  </div>
</div>

解决方法

从上面的链接,如果你在类Application Application Rails ::应用程序config / application.rb
config.action_view.field_error_proc = Proc.new { |html_tag,instance| 
  "<div class=\"field_with_errors control-group error\">#{html_tag}</div>".html_safe
}

当验证失败时,您的输入标签将在其周围有一个红色的标记

相关文章

validates:conclusion,:presence=>true,:inclusion=>{...
一、redis集群搭建redis3.0以前,提供了Sentinel工具来监控各...
分享一下我老师大神的人工智能教程。零基础!通俗易懂!风趣...
上一篇博文 ruby传参之引用类型 里边定义了一个方法名 mo...
一编程与编程语言 什么是编程语言? 能够被计算机所识别的表...
Ruby类和对象Ruby是一种完美的面向对象编程语言。面向对象编...