自定义错误消息,除非在Rails 5

时间:2017-02-06 18:06:41

标签: ruby-on-rails

我的模型中有以下验证:

validates :cep, presence: true, :unless => lambda { |o| o.location }

如何自定义验证失败时显示的错误消息?

1 个答案:

答案 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

上的文档