我尝试遵循http://api.rubyonrails.org/classes/ActiveModel/Validator.html,但是我应该放在哪里
class MyValidator < ActiveModel::Validator
def validate(record)
if some_complex_logic
record.errors[:base] = "This record is invalid"
end
end
private
def some_complex_logic
# ...
end
end
最佳答案
This guy将它们放在app/validators/
下,自从我看到该博客帖子以来,我也这样做了。
关于ruby-on-rails - ActiveModel::Validator放在哪里?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/4468644/