我的模型中有以下验证:
validates :cep, presence: true, :unless => lambda { |o| o.location }
如何自定义验证失败时显示的错误消息?
答案 0 :(得分:1)
将foreach($rows as $k=>$row1) { //add index $k to use an automatic autoincrement for the key
//and put it inside each fields
$response[$k]['id'] = $row1['id'];
$response[$k]['category'][] = $row1['category'];
$response[$k]['text'] = $row1['text'];
$response[$k]['image'] = $row1['image'];
}
选项传递给message
方法。
validates
有关详情,请参阅validates :cep, presence: { message: 'Your custom error message' }, unless: lambda { |o| o.location }
here