Rails4验证唯一性范围检查两个以上的条件

时间:2015-01-14 05:09:33

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-4

我在模型

中对我的电子邮件进行了以下验证
:uniqueness => { :scope => :company_id, :message => "Email has already been taken" }

如何为验证唯一性提供两个范围条件

:uniqueness => {:scope => :company_id and :status => 0,:message => “已经收到电子邮件”}

1 个答案:

答案 0 :(得分:0)

试试这个

:uniqueness => { :scope => [:company_id, :status], :message => "Email has already been taken"}, if: Proc.new { |obj| obj.status == 0 }