(A)所示:這些rails 3.1驗證哪個更好?
validates :network_id, :numericality => true
validates :direct_url, :presence => true
validates :domain_name, :presence => true
validates :merchant_id, :numericality => true
validates :is_paid_merchant, :presence => true
validates :is_top_merchant, :presence => true
validates :last_months_revenue, :presence => true,
:numericality => true
validates :name, :presence => true,
:length => { :maximum => 50 }
validates :primary_category_id, :numericality => true
validates :url, :presence => true
validates :url_tag, :presence => true,
:length => { :maximum => 45 }
-OR-
(B)是這樣的:
validates :network_id,
:merchant_id,
:last_months_revenue,
:primary_category_id, :numericality => true
validates :direct_url,
:domain_name,
:is_paid_merchant,
:is_top_merchant,
:last_months_revenue,
:name,
:url,
:url_tag, :presence => true
validates :name, :length => { :maximum => 50 }
validates :url_tag, :length => { :maximum => 45 }
在每個字段都有它自己的只會驗證子句所述第一殼體和所述第二它基於正在驗證的內容(具有多次驗證的字段會多次出現)。第一種情況也是按字母順序排列的,所以對於跳到特定領域有一些幫助。
- 或 -
(C)我只是太肛門固關於我的代碼是如何讀取和外觀?
「因爲我不得不通過30行代碼來了解在單個字段上設置了哪些驗證。」這足夠令人信服!哈哈 – Hopstream