我有一個類,我正在使用驗證方法來檢查長度,我想注入實際長度到錯誤消息。這可能嗎?活動記錄驗證:長度錯誤信息顯示實際長度?
這裏是我當前的類,我現在用的驗證:
class Something
validates :summary, :detail, :length => {
:in => 300..500,
:too_short => "must have at least %{count} letters",
:too_long => "must have at most %{count} letters"
}
和錯誤消息顯示:
2 errors prohibited this job from being saved.
Summary must have at least 300 letters
Detail must have at least 300 letters
但是我想表明:
...
Summary is only 250 letters and must have at least 300 letters
...
有趣的問題@CarsonCole –