Closed tute closed 12 years ago
I'm not sure using ActiveModel's namespace for this is a good idea, because then any other ActiveModel-compatible library that wants to define a uniqueness validation the same way will conflict with Ambry.
Although it's quite ugly, Active Model provides a solution for this, which would be to reference with validation with the namespace like this:
validates :"ambry/validators/uniqueness" => true
I think in this case aesthetics are less important than compatibility, particularly when there's already a more aesthetic alternative available by using validates_uniqueness_of
rather than the validates
form.
I agree Norman, I'll close the Pull Request. Thanks for your time!
Maybe we should at least document this? It's pretty counterintuitive and I only learned about this because your pull request made me look through the documentation.
Should we add notes in the README, or in code? Now I don't remember if I've seen through code/tests this feature, maybe it's good to show it in the README (with the comment in question of course).
Moved
Ambry::Validations::Uniqueness
toActiveModel::Validations::UniquenessValidator
to supportvalidates :attr, :uniqueness => true
syntax apart fromvalidates_uniqueness_of
(ActiveModel#validates
looks for custom validations inActiveModel::Validations::#{CustomValidator}Validator
).