我有这个很好的类ErrorFormBuilder,它允许我在窗体视图中的相应字段附近添加错误描述:
class ErrorFormBuilder < ActionView::Helpers::FormBuilder
#Adds error message directly inline to a form label
#Accepts all the options normall passed to form.label as well as:
# :hide_errors - true if you don't want errors displayed on this label
# :additional_text - Will add additional text after the error message or after the label if no errors
def label(method, text = nil, options = {})
#Check to see if text for this label has been supplied and humanize the field name …Run Code Online (Sandbox Code Playgroud)