How to Highlight Fields on Rails Validation Errors

后端 未结 3 1592
梦毁少年i
梦毁少年i 2020-12-31 15:11

How do you display form field highlighting for fields that fail validation errors in Rails 3.1? I know that scaffolding automatically generates the css and controller code t

3条回答
  •  忘掉有多难
    2020-12-31 15:35

    I had to do this (resource.errors[field_name].length > 0) to get it to work:

    def field_class(resource, field_name) if resource.errors[field_name].length > 0 return " custom_error1 ".html_safe else return "".html_safe end end

提交回复
热议问题