2
我正在编写我的第一个自定义rails验证,并且如果它们返回false,我想用html“error”类标记违规类 - 我无法弄清楚如何做到这一点。下面的相关验证代码 - 任何帮助表示赞赏。Rails 3自定义验证:突出显示违规字段
(如果它的确与众不同,我使用jQuery)
validates_each :shop do |record, attr, value|
shopvar = record.shops.map{ |s| s.email.downcase.strip }
if shopvar.count != shopvar.uniq.count
record.errors.add(attr, 'has the same email address entered more than once')
#record.errors[attr] << "You have entered this shop in the form twice"
end
end