how to customize rails activerecord validation error message to show attribute value

后端 未结 3 915
甜味超标
甜味超标 2020-12-08 20:08

When a user tries to create a record with a name that already exists, I want to show an error message like:

name \"some name\" has already been taken

3条回答
  •  情话喂你
    2020-12-08 20:17

    What version of Rails do you use?

    If Rails 3. then as i understand you should use :message => '%{value} has already been taken'. I am not sure about Rails 2.3. - but in any case you can create your own custom validation that performs what you need.

提交回复
热议问题