如何显示字段旁边的错误消息 [英] How to Show Error Messages Next to Field
本文介绍了如何显示字段旁边的错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有输入字段/标签的表单等等。我如何在错误字段旁显示错误消息?而不是在顶部聚集在一起?
I have a form with input fields/labels etc. How do I get the error message to show up next to the field? instead of clumped together at the top?
我正在使用设计,rails 3
I am using devise, rails 3
我在我的表单顶部:
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
- if resource.errors.any?
#errorExplanation
%h2
= pluralize(resource.errors.count, "error")
prevented this user from being saved:
%ul
- resource.errors.full_messages.each do |msg|
%li
= msg
推荐答案
你可以使用这个
- if @resource.errors[:field_name]
...
还有用的链接:
http://guides.rubyonrails.org/active_record_validations.html#working-with-validation-errors
这篇关于如何显示字段旁边的错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文