我正在尝试使用with_options将管理员用户的条件验证分组在一起。 第二次验证用户名唯一性最终会覆盖with_options条件。是否可以结合with_options和:if for conditional validation?
有没有更好的方法来做到这一点?或者我应该忘记with_options并编写两个单独的语句?
with_options :if => Proc.new { |user| user.admin? } do |admin|
admin.validates :email, :presence => true
admin.validates :username, :uniqueness => true, :if => Proc.new { |user| user.category == "customized_username" }
end