2
我已經以依賴的方式實現了驗證,例如start_date格式無效,所以我不想在start_date上運行其他驗證。在rails模型中更改自定義驗證的優先級
validates_format_of :available_start_date, :with => /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}((((\-|\+){1}\d{2}:\d{2}){1})|(z{1}|Z{1}))$/, :message => "must be in the following format: 2011-08-25T00:00:00-04:00"
此檢查特定的格式,然後我定製的,要求應該更高版本上運行的驗證方法。
def validate
super
check_offer_dates
end
我用self.errors [「起始日期」]來檢查錯誤對象包含錯誤,它應該跳過其他驗證上相同的參數,如果它不是空的。
但問題是def驗證首先被調用,然後是validates_format_of。我怎樣才能改變這一點,以便流程能夠實現。