Validates with :if

前端 未结 4 459
深忆病人
深忆病人 2021-01-02 01:07

I\'m trying to create a condition in which the attribute \'one\' is zero and the attribute \'two\' is one, then a model is not valid. But when I make:

Model.         


        
4条回答
  •  难免孤独
    2021-01-02 01:48

    You can validate it in one line:

    validates :one, :two, :presence => true, :if => Proc.new { |a| !(a.one == 0 && a.two == 1) }
    

提交回复
热议问题