Rails 3自定义验证器应存储在哪里?
问题描述:
我已经看到文档/网站显示自定义验证器应该放在 / lib
或 / lib / validators
中>项目目录。我发现(通过阅读另一篇文章的答案)它们似乎只在 config / initializers
中起作用。是否有人知道或有一个指向自定义验证器应该住在哪里的官方文档的指针?
I've seen docs/websites show that custom validators should go in a /lib
or /lib/validators
directory of a project. I've found (by reading an answer to another post) that they only seem to work in config/initializers
. Does anyone know, or have a pointer to official documentation that shows where custom validators should live?
答
如果放置自定义验证器在 app / validators
中,它们将自动加载而无需更改您的 config / application.rb
文件。
If you place your custom validators in app/validators
they will be automatically loaded without needing to alter your config/application.rb
file.