Rails validation error messages: Displaying only one error message per field

后端 未结 13 818
情话喂你
情话喂你 2020-12-07 17:08

Rails displays all validation error messages associated with a given field. If I have three validates_XXXXX_of :email, and I leave the field blank, I get three

相关标签:
13条回答
  • 2020-12-07 18:05

    I think the easiest way is to use allow_bank option. For example, to avoid display the message that the name is too short when the field is left blank, you can do the following:

    validates_length_of :name, allow_blank:true, :in => 6..30
    
    0 讨论(0)
提交回复
热议问题