当我尝试验证时,我收到此错误。我试图验证字符串是否不在数据库中。
这是我的模特
class Location < Locations::Location
validate do
#strong URL check for url_prefix
errors.add(:url_prefix, "URL already taken") if self.url_prefix.valid? && is_on_web;
end
end
答案 0 :(得分:3)
改为使用,
validates :url_prefix, :uniqueness => { :message => "URL already taken and is online" }
更新:
可以添加条件验证来解决您的第二个问题,
validates :url_prefix, :uniqueness => { :message => "URL already taken and is online" }, :if => :is_on_web?