上的條件我想驗證這兩個屬性的存在:shipping_cost
和:shipping_cost_anywhere
如果屬性:shipping
等於true
。而如果validates_presence_of如果rails 3.2和mongoid + simple_form
我有這個在我的模型,但不是爲我工作的罰款:
validates_presence_of :shipping_cost, :shipping_cost_anywhere, :allow_blank => "true" if :shipping == "true"
這是我的:運費屬性:
field :shipping, :type => Boolean, :default => "false"
我該怎麼辦呢?
謝謝!
已編輯。
我使用mongoid和simple_form寶石
請更具體地說明它如何不適合你。這可以更容易地猜出你想表達的內容。 :) – flooooo
謝謝,如果我將字段':shipping'設置爲true,那麼字段':shipping_cost'和':shipping_cost_anywhere'未驗證。 – hyperrjas