Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有一种方法可以验证回调方法返回的布尔值中的单个字段?就像是:
validate_with_callback :title, :callback_method, '错误信息'
不必完全相同,但是否有类似的内置导轨?
我想你可以这样做:
def self.validate_with_callback(attr, method, error) validate do |record| record.errors.add attr, error unless record.send(method) end end
但这只是一个愚蠢的包装器validate,所以我直接调用它。
validate