客户端验证 gem:错误消息在开发环境中显示两次
我将客户端验证 gem (v3.1.0) 与 Rails 3.1.1 结合使用,每当我跳出表单字段时,在我的开发环境中,每个错误消息都会显示两次。在我的登台和生产环境中,它们仅显示一次。这让我抓狂,我不明白为什么。
典型的表单字段如下所示:
<div class="label">
<label for="user_first_name">First name</label>
</div>
<div class="field">
<input class="text" data-validate="true" id="user_first_name" name="user[first_name]" size="30" type="text" />
</div>
验证发生后:
<div class="label">
<div class="field_with_errors"><div class="field_with_errors"><label for="user_first_name">First name</label></div></div>
</div>
<div class="field">
<div class="field_with_errors"><div class="field_with_errors"><input class="text" data-validate="true" id="user_first_name" name="user[first_name]" size="30" type="text"><label for="user_first_name" class="message">can't be blank</label></div><label for="user_first_name" class="message">can't be blank</label></div>
</div>
我不明白开发中发生的事情与暂存/生产不同,除了资产管道的服务不同之外。还有其他人遇到过这种情况吗?我在网上找不到任何相关信息。
I am using the client side validations gem (v3.1.0) with Rails 3.1.1 and whenever I tab out of a form field, in my development environment every error message is displayed twice. In my staging and production environments, they are only shown once. This is driving me nuts and I can't figure out WHY.
A typical form field looks like this:
<div class="label">
<label for="user_first_name">First name</label>
</div>
<div class="field">
<input class="text" data-validate="true" id="user_first_name" name="user[first_name]" size="30" type="text" />
</div>
After a validation occurs:
<div class="label">
<div class="field_with_errors"><div class="field_with_errors"><label for="user_first_name">First name</label></div></div>
</div>
<div class="field">
<div class="field_with_errors"><div class="field_with_errors"><input class="text" data-validate="true" id="user_first_name" name="user[first_name]" size="30" type="text"><label for="user_first_name" class="message">can't be blank</label></div><label for="user_first_name" class="message">can't be blank</label></div>
</div>
I do not understand what is going on in development that is different from staging/production other than the asset pipeline getting served differently. Has anyone else encountered this? I have not been able to find anything on it in online.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您预编译了资产吗?就我而言,这就是问题所在。只需删除 public/assets 文件夹,验证就应该只显示一次。
Did you precompile the assets? In my case, that was the problem. Simply remove the public/assets folder and validations should display only once.